cache

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: BSD-3-Clause Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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()

	// Returns the number of elements currently in the cache
	Len() int

	// Returns fraction of cache currently filled (0 --> 1)
	PortionFilled() float64
}

Cacher acts as a best effort key value store.

func NewSizedLRU added in v1.1.11

func NewSizedLRU[K comparable, V any](maxSize int, size func(K, V) int) Cacher[K, V]

type Empty added in v0.1.1

type Empty[K any, V any] struct{}

func (*Empty[K, _]) Evict added in v0.1.1

func (*Empty[K, _]) Evict(K)

func (*Empty[_, _]) Flush added in v0.1.1

func (*Empty[_, _]) Flush()

func (*Empty[K, V]) Get added in v0.1.1

func (*Empty[K, V]) Get(K) (V, bool)

func (*Empty[_, _]) Len added in v0.1.1

func (*Empty[_, _]) Len() int

func (*Empty[_, _]) PortionFilled added in v0.1.1

func (*Empty[_, _]) PortionFilled() float64

func (*Empty[K, V]) Put added in v0.1.1

func (*Empty[K, V]) Put(K, V)

type LRU

type LRU[K comparable, V any] struct {

	// If set to <= 0, will be set internally to 1.
	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[_, _]) Flush

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

func (*LRU[K, V]) Get

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

func (*LRU[_, _]) Len added in v1.1.11

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

func (*LRU[_, _]) PortionFilled added in v1.1.11

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

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