Documentation
¶
Index ¶
- type EvictCallback
- type LRU
- func (c *LRU[K, V]) Add(key K, value V) (evicted bool)
- func (c *LRU[K, V]) Cap() int
- func (c *LRU[K, V]) Contains(key K) (ok bool)
- func (c *LRU[K, V]) Get(key K) (value V, ok bool)
- func (c *LRU[K, V]) GetOldest() (key K, value V, ok bool)
- func (c *LRU[K, V]) Init() *LRU[K, V]
- func (c *LRU[K, V]) Keys() []K
- func (c *LRU[K, V]) Len() int
- func (c *LRU[K, V]) Peek(key K) (value V, ok bool)
- func (c *LRU[K, V]) Purge()
- func (c *LRU[K, V]) Remove(key K) (present bool)
- func (c *LRU[K, V]) RemoveOldest() (key K, value V, ok bool)
- func (c *LRU[K, V]) Resize(size int) (evicted int)
- func (c *LRU[K, V]) SetEvictCallback(onEvict EvictCallback[K, V]) *LRU[K, V]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EvictCallback ¶
type EvictCallback[K comparable, V any] func(key K, value V)
EvictCallback is used to get a callback when a cache entry is evicted
type LRU ¶
type LRU[K comparable, V any] struct { // contains filtered or unexported fields }
LRU implements a non-thread safe fixed size LRU cache
func NewLRU ¶ added in v1.2.14
func NewLRU[K comparable, V any](size int) *LRU[K, V]
NewLRU constructs an LRU of the given size
func (*LRU[K, V]) Contains ¶
Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.
func (*LRU[K, V]) Keys ¶
func (c *LRU[K, V]) Keys() []K
Keys returns a slice of the keys in the cache, from oldest to newest.
func (*LRU[K, V]) Peek ¶
Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
func (*LRU[K, V]) Remove ¶
Remove removes the provided key from the cache, returning if the key was contained.
func (*LRU[K, V]) RemoveOldest ¶
RemoveOldest removes the oldest item from the cache.
func (*LRU[K, V]) SetEvictCallback ¶
func (c *LRU[K, V]) SetEvictCallback(onEvict EvictCallback[K, V]) *LRU[K, V]
SetEvictCallback sets a callback when a cache entry is evicted