cache

package
v1.4.9-rc.4 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: BSD-3-Clause Imports: 4 Imported by: 131

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CacherTests = []struct {
	Size int
	Func func(t *testing.T, c Cacher)
}{
	{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)

func TestEviction added in v1.1.4

func TestEviction(t *testing.T, cache Cacher)

Types

type Cacher

type Cacher interface {
	// Put inserts an element into the cache. If spaced is required, elements will
	// be evicted.
	Put(key, value interface{})

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

	// Evict removes the specified entry from the cache
	Evict(key interface{})

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

Cacher acts as a best effort key value store. Keys must be comparable, as defined by https://golang.org/ref/spec#Comparison_operators.

type Deduplicator

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

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

Deduplicator acts as a best effort deduplication service

type Evictable

type Evictable interface {
	// Key must return a comparable value as defined by
	// https://golang.org/ref/spec#Comparison_operators.
	Key() interface{}
	Evict()
}

Evictable allows the object to be notified when it is evicted

type EvictableLRU

type EvictableLRU struct {
	Size int
	// contains filtered or unexported fields
}

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

func (*EvictableLRU) Deduplicate

func (c *EvictableLRU) Deduplicate(value Evictable) Evictable

Deduplicate implements the Deduplicator interface

func (*EvictableLRU) Flush

func (c *EvictableLRU) Flush()

Flush implements the Deduplicator interface

type LRU

type LRU 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) Evict

func (c *LRU) Evict(key interface{})

Evict implements the cache interface

func (*LRU) Flush

func (c *LRU) Flush()

Flush implements the cache interface

func (*LRU) Get

func (c *LRU) Get(key interface{}) (interface{}, bool)

Get implements the cache interface

func (*LRU) Put

func (c *LRU) Put(key, value interface{})

Put implements the cache interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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