Documentation
¶
Overview ¶
Package lru provides the ONE standard LRU cache implementation using container package.
Index ¶
- type Cache
- func (c *Cache[K, V]) Clear()
- func (c *Cache[K, V]) Contains(key K) bool
- func (c *Cache[K, V]) Delete(key K)
- func (c *Cache[K, V]) Evict(key K)
- func (c *Cache[K, V]) Flush()
- func (c *Cache[K, V]) Get(key K) (value V, ok bool)
- func (c *Cache[K, V]) Len() int
- func (c *Cache[K, V]) PortionFilled() float64
- func (c *Cache[K, V]) Put(key K, value V)
- func (c *Cache[K, V]) Size() int
- type SizedCache
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 }
Cache is the standard LRU cache - ONE implementation, no duplicates
func NewCache ¶
func NewCache[K comparable, V any](size int) *Cache[K, V]
NewCache creates a new LRU cache - THE standard way
func NewCacheWithOnEvict ¶
func NewCacheWithOnEvict[K comparable, V any](size int, onEvict func(K, V)) *Cache[K, V]
NewCacheWithOnEvict creates cache with eviction callback
func (*Cache[K, V]) Evict ¶
func (c *Cache[K, V]) Evict(key K)
Evict removes a key from cache (required by Cacher interface)
func (*Cache[K, V]) Flush ¶
func (c *Cache[K, V]) Flush()
Flush removes all entries from cache (required by Cacher interface)
func (*Cache[K, V]) PortionFilled ¶
PortionFilled returns fraction of cache currently filled (0 --> 1)
type SizedCache ¶
type SizedCache[K comparable, V any] struct { // contains filtered or unexported fields }
SizedCache is an LRU cache bounded by total size rather than entry count.
func NewSizedCache ¶
func NewSizedCache[K comparable, V any](maxSize int, sizeFn func(K, V) int) *SizedCache[K, V]
NewSizedCache creates a size-bounded LRU cache.
func (*SizedCache[K, V]) Evict ¶
func (c *SizedCache[K, V]) Evict(key K)
Evict removes a key from the cache.
func (*SizedCache[K, V]) Get ¶
func (c *SizedCache[K, V]) Get(key K) (V, bool)
Get retrieves a value and marks it as most recently used.
func (*SizedCache[K, V]) PortionFilled ¶
func (c *SizedCache[K, V]) PortionFilled() float64
PortionFilled returns the ratio of size used to max size.
func (*SizedCache[K, V]) Put ¶
func (c *SizedCache[K, V]) Put(key K, value V)
Put inserts or replaces a value.