lru
Package lru
import "github.com/luxfi/node/cache/lru"Types
Cache
Cache is a key value store with bounded size. If the size is attempted to be exceeded, then an element is removed from the cache before the insertion is done, based on evicting the least recently used value.
func NewCache[K comparable, V any](size int) *Cache[K, V]func NewCacheWithOnEvict[K comparable, V any](size int, onEvict func(K, V)) *Cache[K, V]func (c *Cache[K, _]) Evict(key K)func (c *Cache[_, _]) Flush()func (c *Cache[K, V]) Get(key K) (V, bool)func (c *Cache[_, _]) Len() intfunc (c *Cache[_, _]) PortionFilled() float64func (c *Cache[K, V]) Put(key K, value V)Deduplicator
Deduplicator is an LRU cache that notifies the objects when they are evicted.
Deprecated: Remove this once the vertex state no longer uses it.
func NewDeduplicator[K comparable, V Evictable[K]](size int) *Deduplicator[K, V]func (d *Deduplicator[_, V]) Deduplicate(value V) Vfunc (d *Deduplicator[_, _]) Flush()Evictable
Evictable allows the object to be notified when it is evicted
Deprecated: Remove this once the vertex state no longer uses it.
SizedCache
SizedCache is a key value store with bounded size. If the size is attempted to be exceeded, then elements are removed from the cache until the bound is honored, based on evicting the least recently used value.
func NewSizedCache[K comparable, V any](maxSize int, size func(K, V) int) *SizedCache[K, V]func (c *SizedCache[K, V]) Evict(key K)func (c *SizedCache[K, V]) Flush()func (c *SizedCache[K, V]) Get(key K) (V, bool)func (c *SizedCache[_, _]) Len() intfunc (c *SizedCache[_, _]) PortionFilled() float64func (c *SizedCache[K, V]) Put(key K, value V)