Documentation
¶
Overview ¶
Package lru provides a generic least-recently-used cache.
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 { // contains filtered or unexported fields }
Cache is a generic LRU cache that is NOT goroutine-safe. Callers must provide their own synchronization.
func New ¶
func New[K comparable, V any](maxSize int, onEvict func(K, V)) *Cache[K, V]
New creates a new LRU cache with the given maximum size. If onEvict is non-nil, it is called whenever an entry is evicted.
func (*Cache[K, V]) Get ¶
Get returns the value for key and marks it as recently used. The second return value reports whether the key was found.
func (*Cache[K, V]) Keys ¶
func (c *Cache[K, V]) Keys() []K
Keys returns all keys in order from most recently used to least.
Click to show internal directories.
Click to hide internal directories.