Documentation
¶
Overview ¶
Package lru implements a LRU cache. It is a generic vesion of github.com/golang/groupcache/lru.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // MaxEntries is the maximum number of cache entries before // an item is evicted. Zero means no limit. MaxEntries int // OnEvicted optionally specifies a callback function to be // executed when an entry is purged from the cache. OnEvicted func(key K, value V) // contains filtered or unexported fields }
Cache is an LRU cache. It is not safe for concurrent access.
func New ¶
func New[K comparable, V any](maxEntries int) *Cache[K, V]
New creates a new Cache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.
func (*Cache[K, V]) Clear ¶
func (c *Cache[K, V]) Clear()
Clear purges all stored items from the cache.
func (*Cache[K, V]) Remove ¶
func (c *Cache[K, V]) Remove(key K)
Remove removes the provided key from the cache.
func (*Cache[K, V]) RemoveOldest ¶
func (c *Cache[K, V]) RemoveOldest()
RemoveOldest removes the oldest item from the cache.
Click to show internal directories.
Click to hide internal directories.