ttlcache

package
v1.57.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2025 License: GPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReasonTimedOut = DeallocationReason(iota)
	ReasonDeleted  = DeallocationReason(iota)
)
View Source
const DefaultTTL time.Duration = time.Nanosecond * 1
View Source
const NoTTL time.Duration = 0

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func New

func New[K comparable, V any](options Options[K, V]) *Cache[K, V]

func (*Cache[K, V]) Close

func (c *Cache[K, V]) Close()

func (*Cache[K, V]) Delete

func (c *Cache[K, V]) Delete(key K)

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(key K) (V, bool)

func (*Cache[K, V]) GetItem

func (c *Cache[K, V]) GetItem(key K) (Item[V], bool)

func (*Cache[K, V]) GetKeys

func (c *Cache[K, V]) GetKeys() []K

func (*Cache[K, V]) GetOrSet

func (c *Cache[K, V]) GetOrSet(key K, value V, duration time.Duration) (V, bool)

func (*Cache[K, V]) GetOrSetItem

func (c *Cache[K, V]) GetOrSetItem(key K, value V, duration time.Duration) (Item[V], bool)

func (*Cache[K, V]) Set

func (c *Cache[K, V]) Set(key K, value V, duration time.Duration) bool

func (*Cache[K, V]) SetItem

func (c *Cache[K, V]) SetItem(key K, value V, duration time.Duration) Item[V]

type DeallocationFunc

type DeallocationFunc[K comparable, V any] func(key K, value V, reason DeallocationReason)

type DeallocationReason

type DeallocationReason int

type Item

type Item[V any] struct {
	// contains filtered or unexported fields
}

func (*Item[V]) GetDuration

func (i *Item[V]) GetDuration() time.Duration

func (*Item[V]) GetTime

func (i *Item[V]) GetTime() time.Time

func (*Item[V]) GetValue

func (i *Item[V]) GetValue() V

type Options

type Options[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (Options[K, V]) DisableUpdateTime

func (o Options[K, V]) DisableUpdateTime(val bool) Options[K, V]

func (Options[K, V]) SetDeallocationFunc

func (o Options[K, V]) SetDeallocationFunc(f DeallocationFunc[K, V]) Options[K, V]

func (Options[K, V]) SetDefaultTTL

func (o Options[K, V]) SetDefaultTTL(d time.Duration) Options[K, V]

func (Options[K, V]) SetTimerResolution

func (o Options[K, V]) SetTimerResolution(d time.Duration) Options[K, V]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL