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 struct {
// contains filtered or unexported fields
}
A Cache is a fixed-size in-memory LRU cache.
func New ¶
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) Get ¶
func (c *Cache) Get(key any) any
Get retrieves the value for the specified key, or nil if the key is not found.
If the key is found, its access time is updated.
func (*Cache) 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.