Documentation ¶
Overview ¶
Package lru implements an LRU cache.
Index ¶
- type LRU
- func (c *LRU[Key, Value]) Add(key Key, value Value)
- func (c *LRU[Key, Value]) ApplyRO(f func(generic_lru.Cache[Key, Value]))
- func (c *LRU[Key, Value]) ApplyRW(f func(generic_lru.Cache[Key, Value]))
- func (c *LRU[Key, Value]) Clear()
- func (c *LRU[Key, Value]) Container() (interface{}, error)
- func (c *LRU[Key, Value]) Get(key Key) (value Value, ok bool)
- func (c *LRU[Key, Value]) GetOldest() (key Key, value Value, ok bool)
- func (c *LRU[Key, Value]) Len() int
- func (c *LRU[Key, Value]) Remove(key Key) (value Value, ok bool)
- func (c *LRU[Key, Value]) RemoveOldest() (key Key, value Value, ok bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LRU ¶
type LRU[Key comparable, Value 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 Key, value Value) // contains filtered or unexported fields }
LRU is an LRU cache. It is not safe for concurrent access.
func New ¶
func New[Key comparable, Value any](maxEntries int) *LRU[Key, Value]
New creates a new LRU. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.
func NewWithOnEvicted ¶ added in v1.0.1
func NewWithOnEvicted[Key comparable, Value any](maxEntries int, onEvicted func(Key, Value)) *LRU[Key, Value]
New creates a new LRU with OnEvicted. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.
func (*LRU[Key, Value]) Add ¶
func (c *LRU[Key, Value]) Add(key Key, value Value)
Add adds a value to the cache.
func (*LRU[Key, Value]) ApplyRO ¶
func (c *LRU[Key, Value]) ApplyRO(f func(generic_lru.Cache[Key, Value]))
func (*LRU[Key, Value]) ApplyRW ¶
func (c *LRU[Key, Value]) ApplyRW(f func(generic_lru.Cache[Key, Value]))
func (*LRU[Key, Value]) Clear ¶
func (c *LRU[Key, Value]) Clear()
Clear purges all stored items from the cache.
func (*LRU[Key, Value]) RemoveOldest ¶
RemoveOldest removes the oldest item from the cache.
Click to show internal directories.
Click to hide internal directories.