Documentation
¶
Overview ¶
Package lru implements a 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 }
A Cache is a map that retains a limited number of items. It must be initialized with New, providing a maximum capacity for the cache. Only the least recently used items are retained.
func New ¶
func New[K comparable, V any](icap int) *Cache[K, V]
New must be used to create a new Cache.
func (*Cache[K, V]) ConsistencyCheck ¶
ConsistencyCheck runs a series of checks to ensure that the cache's data structures are consistent. It is not normally required, and it is primarily used in testing.
func (*Cache[K, V]) Get ¶
Get returns the value stored in the cache. If the item isn't present, it will return false.
func (*Cache[K, V]) Has ¶
Has returns true if the cache has an entry for k. It will not update the timestamp on the item.
type StringKeyCache ¶
StringKeyCache is a convenience wrapper for cache keyed by string.
func NewStringKeyCache ¶
func NewStringKeyCache[V any](icap int) *StringKeyCache[V]
NewStringKeyCache creates a new LRU cache keyed by string.