lru

package
v1.2.10 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

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]

func NewCacheWithOnEvict added in v1.2.10

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 added in v1.2.10

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

func (*Cache[K, V]) Put

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

type Deduplicator deprecated added in v1.2.10

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 added in v1.2.10

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 added in v1.2.10

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 added in v1.2.10

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

Flush removes all entries from the cache

type Evictable deprecated added in v1.2.10

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 added in v1.2.10

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 added in v1.2.10

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

func (*SizedCache[K, V]) Evict added in v1.2.10

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

func (*SizedCache[K, V]) Flush added in v1.2.10

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

func (*SizedCache[K, V]) Get added in v1.2.10

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

func (*SizedCache[_, _]) Len added in v1.2.10

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

func (*SizedCache[_, _]) PortionFilled added in v1.2.10

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

func (*SizedCache[K, V]) Put added in v1.2.10

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