Documentation ¶
Index ¶
- type Cache
- func (c *Cache[K, V]) Add(key K, value V) bool
- func (c *Cache[K, V]) CAS(key K, old V, new V, cmp func(V, V) bool) bool
- func (c *Cache[K, V]) Cap() (l int)
- func (c *Cache[K, V]) Clear()
- func (c *Cache[K, V]) Get(key K) (V, bool)
- func (c *Cache[K, V]) Has(key K) (ok bool)
- func (c *Cache[K, V]) Init(len, cap int, ttl time.Duration)
- func (c *Cache[K, V]) Invalidate(key K) (ok bool)
- func (c *Cache[K, V]) Len() (l int)
- func (c *Cache[K, V]) Set(key K, value V)
- func (c *Cache[K, V]) SetEvictionCallback(hook func(K, V))
- func (c *Cache[K, V]) SetInvalidateCallback(hook func(K, V))
- func (c *Cache[K, V]) SetTTL(ttl time.Duration, update bool)
- func (c *Cache[K, V]) Start(freq time.Duration) (ok bool)
- func (c *Cache[K, V]) Stop() (ok bool)
- func (c *Cache[K, V]) Swap(key K, swp V) V
- func (c *Cache[K, V]) Sweep(now time.Time)
- type Entry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[Key comparable, Value any] struct { // TTL is the cache item TTL. TTL time.Duration // Evict is the hook that is called when an item is evicted from the cache. Evict func(Key, Value) // Invalid is the hook that is called when an item's data in the cache is invalidated, includes Add/Set. Invalid func(Key, Value) // Cache is the underlying hashmap used for this cache. Cache maps.LRUMap[Key, *Entry[Key, Value]] // Pool is a memory pool of Entry objects. Pool []*Entry[Key, Value] // Embedded mutex. sync.Mutex // contains filtered or unexported fields }
Cache is the underlying Cache implementation, providing both the base Cache interface and unsafe access to underlying map to allow flexibility in building your own.
func New ¶
New returns a new initialized Cache with given initial length, maximum capacity and item TTL.
func (*Cache[K, V]) Init ¶
Init will initialize this cache with given initial length, maximum capacity and item TTL.
func (*Cache[K, V]) Invalidate ¶
Invalidate: implements cache.Cache's Invalidate().
func (*Cache[K, V]) Set ¶
func (c *Cache[K, V]) Set(key K, value V)
Set: implements cache.Cache's Set().
func (*Cache[K, V]) SetEvictionCallback ¶
func (c *Cache[K, V]) SetEvictionCallback(hook func(K, V))
SetEvictionCallback: implements cache.Cache's SetEvictionCallback().
func (*Cache[K, V]) SetInvalidateCallback ¶
func (c *Cache[K, V]) SetInvalidateCallback(hook func(K, V))
SetInvalidateCallback: implements cache.Cache's SetInvalidateCallback().
Click to show internal directories.
Click to hide internal directories.