cache

package
v1.9.4-rc.8 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2022 License: BSD-3-Clause Imports: 4 Imported by: 108

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CacherTests = []struct {
	Size int
	Func func(t *testing.T, c Cacher[ids.ID, int])
}{
	{Size: 1, Func: TestBasic},
	{Size: 2, Func: TestEviction},
}

CacherTests is a list of all Cacher tests

Functions

func TestBasic added in v1.1.4

func TestBasic(t *testing.T, cache Cacher[ids.ID, int])

func TestEviction added in v1.1.4

func TestEviction(t *testing.T, cache Cacher[ids.ID, int])

Types

type Cacher

type Cacher[K comparable, V any] interface {
	// Put inserts an element into the cache. If space is required, elements will
	// be evicted.
	Put(key K, value V)

	// Get returns the entry in the cache with the key specified, if no value
	// exists, false is returned.
	Get(key K) (V, bool)

	// Evict removes the specified entry from the cache
	Evict(key K)

	// Flush removes all entries from the cache
	Flush()
}

Cacher acts as a best effort key value store.

type Deduplicator

type Deduplicator[K comparable, _ Evictable[K]] interface {
	// Deduplicate returns either the provided value, or a previously provided
	// value with the same ID that hasn't yet been evicted
	Deduplicate(Evictable[K]) Evictable[K]

	// Flush removes all entries from the cache
	Flush()
}

Deduplicator acts as a best effort deduplication service

type Evictable

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

Evictable allows the object to be notified when it is evicted

type EvictableLRU

type EvictableLRU[T comparable, _ Evictable[T]] struct {
	Size int
	// contains filtered or unexported fields
}

EvictableLRU is an LRU cache that notifies the objects when they are evicted.

func (*EvictableLRU[T, _]) Deduplicate

func (c *EvictableLRU[T, _]) Deduplicate(value Evictable[T]) Evictable[T]

func (*EvictableLRU[_, _]) Flush

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

type LRU

type LRU[K comparable, _ any] struct {
	Size int
	// contains filtered or unexported fields
}

LRU 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 (*LRU[K, _]) Evict

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

func (*LRU[K, _]) Flush

func (c *LRU[K, _]) Flush()

func (*LRU[K, V]) Get

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

func (*LRU[K, V]) Put

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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