Involved Source Fileslru.go Package simplelru provides simple LRU implementation based on build-in container/list.
Package-Level Type Names (total 3)
/* sort by: | */
Type Parameters:
K: comparable
V: any EvictCallback is used to get a callback when a cache entry is evicted
func NewLRU[K, V](size int, onEvict EvictCallback[K, V]) (*LRU[K, V], error)
Type Parameters:
K: comparable
V: any LRU implements a non-thread safe fixed size LRU cache Add adds a value to the cache. Returns true if an eviction occurred. Contains checks if a key is in the cache, without updating the recent-ness
or deleting it for being stale. Get looks up a key's value from the cache. GetOldest returns the oldest entry Keys returns a slice of the keys in the cache, from oldest to newest. Len returns the number of items in the cache. Peek returns the key value (or undefined if not found) without updating
the "recently used"-ness of the key. Purge is used to completely clear the cache. Remove removes the provided key from the cache, returning if the
key was contained. RemoveOldest removes the oldest item from the cache. Resize changes the cache size. Values returns a slice of the values in the cache, from oldest to newest.
func NewLRU[K, V](size int, onEvict EvictCallback[K, V]) (*LRU[K, V], error)
Type Parameters:
K: comparable
V: any LRUCache is the interface for simple LRU cache. Adds a value to the cache, returns true if an eviction occurred and
updates the "recently used"-ness of the key. Checks if a key exists in cache without updating the recent-ness. Returns key's value from the cache and
updates the "recently used"-ness of the key. #value, isFound Returns the oldest entry from the cache. #key, value, isFound Returns a slice of the keys in the cache, from oldest to newest. Returns the number of items in the cache. Returns key's value without updating the "recently used"-ness of the key. Clears all cache entries. Removes a key from the cache. Removes the oldest entry from cache. Resizes cache, returning number evicted Values returns a slice of the values in the cache, from oldest to newest.
Package-Level Functions (only one)
Type Parameters:
K: comparable
V: any NewLRU constructs an LRU of the given size
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.