lru

package
v1.14.1-db-metrics-fix Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2025 License: BSD-3-Clause Imports: 4 Imported by: 8

Documentation

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
}

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

func NewCache[K comparable, V any](size int) *Cache[K, V]

NewCache creates a new LRU cache with the given size.

func NewCacheWithOnEvict

func NewCacheWithOnEvict[K comparable, V any](size int, onEvict func(K, V)) *Cache[K, V]

NewCacheWithOnEvict creates a new LRU cache with the given size and eviction callback.

func (*Cache[K, _]) Evict

func (c *Cache[K, _]) Evict(key K)

func (*Cache[_, _]) Flush

func (c *Cache[_, _]) Flush()

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(key K) (V, bool)

func (*Cache[_, _]) Len

func (c *Cache[_, _]) Len() int

func (*Cache[_, _]) PortionFilled

func (c *Cache[_, _]) PortionFilled() float64

func (*Cache[K, V]) Put

func (c *Cache[K, V]) Put(key K, value V)

type Deduplicator deprecated

type Deduplicator[K comparable, V Evictable[K]] struct {
	// contains filtered or unexported fields
}

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 deprecated

func NewDeduplicator[K comparable, V Evictable[K]](size int) *Deduplicator[K, V]

Deprecated: Remove this once the vertex state no longer uses it.

func (*Deduplicator[_, V]) Deduplicate

func (d *Deduplicator[_, V]) Deduplicate(value V) V

Deduplicate returns either the provided value, or a previously provided value with the same ID that hasn't yet been evicted

func (*Deduplicator[_, _]) Flush

func (d *Deduplicator[_, _]) Flush()

Flush removes all entries from the cache

type Evictable deprecated

type Evictable[K comparable] interface {
	Key() K
	Evict()
}

Evictable allows the object to be notified when it is evicted

Deprecated: Remove this once the vertex state no longer uses it.

type SizedCache

type SizedCache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

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

func NewSizedCache[K comparable, V any](maxSize int, size func(K, V) int) *SizedCache[K, V]

func (*SizedCache[K, V]) Evict

func (c *SizedCache[K, V]) Evict(key K)

func (*SizedCache[K, V]) Flush

func (c *SizedCache[K, V]) Flush()

func (*SizedCache[K, V]) Get

func (c *SizedCache[K, V]) Get(key K) (V, bool)

func (*SizedCache[_, _]) Len

func (c *SizedCache[_, _]) Len() int

func (*SizedCache[_, _]) PortionFilled

func (c *SizedCache[_, _]) PortionFilled() float64

func (*SizedCache[K, V]) Put

func (c *SizedCache[K, V]) Put(key K, value V)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL