Documentation ¶
Overview ¶
The lru package implements a fixed-size in-memory LRU 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 }
A Cache is a fixed-size in-memory LRU cache, storing values of type V keyed by keys of type K.
func New ¶
func New[K comparable, V any](capacity int) *Cache[K, V]
New creates a new Cache with the given capacity, which must be positive.
The cache capacity uses arbitrary units, which are specified during the Set operation.
func (*Cache[K, V]) Get ¶
Get retrieves the value for the specified key. If the key is found, its access time is updated.
The second result reports whether the key was found.
func (*Cache[K, V]) Set ¶
Set stores a value for the specified key, using its given size to update the current cache size, evicting old entries as necessary to fit in the cache capacity.
Size must be a non-negative value. If size is larger than the cache capacity, the value is not stored and the cache is not modified.