Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewcLRU ¶
func NewcLRU[K comparable, V any](size int, onEvict EvictCallback[K, V]) (*cLRU[K, V], error)
NewcLRU constructs an LRU of the given size
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] interface { // Add a key/value, bool if evicted Add(key K, value V) bool // Get key/value, bool if found Get(key K) (value V, ok bool) // Contains checks for key Contains(key K) (ok bool) // Returns key's value without updating the "recently used"-ness of the key. Peek(key K) (value V, ok bool) // Removes a key from the cache. Remove(key K) bool // Removes the oldest entry from cache. RemoveOldest() (K, V, bool) // Returns the oldest entry from the cache. #key, value, isFound GetOldest() (K, V, bool) // Returns a slice of the keys in the cache, from oldest to newest. Keys() []K // Returns the number of items in the cache. Len() int // Clears all cache entries. Purge() // Resizes cache, returning number evicted Resize(int) int // ContainsOrAdd ContainsOrAdd(K, V) (bool, bool) // PeekOrAdd PeekOrAdd(K, V) (V, bool, bool) }
LRU is the interface for simple LRU cache.
Click to show internal directories.
Click to hide internal directories.