Documentation
¶
Index ¶
- type LRU
- func (lru *LRU[K, V]) All() func(yield func(K, V) bool)
- func (lru *LRU[K, V]) Backward() func(yield func(K, V) bool)
- func (lru *LRU[K, V]) Clear()
- func (lru *LRU[K, V]) Get(key K) (value V, ok bool)
- func (lru *LRU[K, V]) Len() int
- func (lru *LRU[K, V]) OnEvicted(cb func(K, V))
- func (lru *LRU[K, V]) Pick(key K) (value V, ok bool)
- func (lru *LRU[K, V]) Remove(key K) (value V, ok bool)
- func (lru *LRU[K, V]) RemoveOldest() (key K, value V, ok bool)
- func (lru *LRU[K, V]) Resize(size int) (evicted int)
- func (lru *LRU[K, V]) Set(key K, value V)
- type MutexLRU
- func (m *MutexLRU[K, V]) All() func(yield func(K, V) bool)
- func (m *MutexLRU[K, V]) Backward() func(yield func(K, V) bool)
- func (m *MutexLRU[K, V]) Clear()
- func (m *MutexLRU[K, V]) Get(key K) (value V, ok bool)
- func (m *MutexLRU[K, V]) Len() int
- func (m *MutexLRU[K, V]) OnEvicted(cb func(K, V))
- func (m *MutexLRU[K, V]) Pick(key K) (value V, ok bool)
- func (m *MutexLRU[K, V]) Remove(key K) (value V, ok bool)
- func (m *MutexLRU[K, V]) RemoveOldest() (key K, value V, ok bool)
- func (m *MutexLRU[K, V]) Resize(size int) (evicted int)
- func (m *MutexLRU[K, V]) Set(key K, value V)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LRU ¶
type LRU[K comparable, V any] struct { // contains filtered or unexported fields }
LRU is a fixed size LRU cache.
func New ¶
func New[K comparable, V any](size int) *LRU[K, V]
New creates a new LRU cache. If size is zero, the LRU has no limit and it's assumed that eviction is done by the caller.
func (*LRU[K, V]) All ¶
Backward returns an iterator over key-value pairs in the lru cache, traversing it from the newest item.
func (*LRU[K, V]) Backward ¶
Backward returns an iterator over key-value pairs in the lru cache, traversing it from the oldest item.
func (*LRU[K, V]) Clear ¶
func (lru *LRU[K, V]) Clear()
Clear purges all stored items from the lru cache.
func (*LRU[K, V]) OnEvicted ¶
func (lru *LRU[K, V]) OnEvicted(cb func(K, V))
OnEvicted optionally specifies a callback function to be executed when an entry is purged from the lru cache.
func (*LRU[K, V]) Pick ¶
Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
func (*LRU[K, V]) RemoveOldest ¶
RemoveOldest removes the oldest item from the cache.
type MutexLRU ¶
type MutexLRU[K comparable, V any] struct { // contains filtered or unexported fields }
MutexLRU is a thread-safe fixed size LRU cache.
func NewWithMutex ¶
func NewWithMutex[K comparable, V any](size int) *MutexLRU[K, V]
NewWithMutex creates a new thread-safe LRU cache. If size is zero, the LRU has no limit and it's assumed that eviction is done by the caller.
func (*MutexLRU[K, V]) All ¶
Backward returns an iterator over key-value pairs in the lru cache, traversing it from the newest item.
func (*MutexLRU[K, V]) Backward ¶
Backward returns an iterator over key-value pairs in the lru cache, traversing it from the oldest item.
func (*MutexLRU[K, V]) Clear ¶
func (m *MutexLRU[K, V]) Clear()
Clear purges all stored items from the lru cache.
func (*MutexLRU[K, V]) OnEvicted ¶
func (m *MutexLRU[K, V]) OnEvicted(cb func(K, V))
OnEvicted optionally specifies a callback function to be executed when an entry is purged from the lru cache.
func (*MutexLRU[K, V]) Pick ¶
Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
func (*MutexLRU[K, V]) RemoveOldest ¶
RemoveOldest removes the oldest item from the cache.