cache

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: BSD-3-Clause Imports: 3 Imported by: 11

Documentation

Overview

Package cache provides caching interfaces and implementations.

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.
	Put(key K, value V)

	// Get returns the entry with the key, if it exists.
	Get(key K) (V, bool)

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

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

	// Len returns the number of elements in the cache.
	Len() int

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

Cacher acts as a best effort key value store.

type DualMapCache

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

DualMapCache is a simple two-map cache placeholder with migration hooks. The implementation is intentionally minimal to preserve API compatibility.

func NewDualMapCache

func NewDualMapCache[K comparable, V any](_ metric.Registry) *DualMapCache[K, V]

NewDualMapCache creates a new DualMapCache. Metrics are optional.

func (*DualMapCache[K, V]) Evict

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

Evict removes the specified entry from the cache.

func (*DualMapCache[K, V]) Flush

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

Flush removes all entries from the cache.

func (*DualMapCache[K, V]) Get

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

Get returns the entry with the key, if it exists.

func (*DualMapCache[K, V]) Len

func (c *DualMapCache[K, V]) Len() int

Len returns the number of elements in the cache.

func (*DualMapCache[K, V]) Migrate

func (c *DualMapCache[K, V]) Migrate()

Migrate is a no-op placeholder for dual-map cache migration.

func (*DualMapCache[K, V]) PortionFilled

func (c *DualMapCache[K, V]) PortionFilled() float64

PortionFilled returns fraction of cache currently filled.

func (*DualMapCache[K, V]) Put

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

Put inserts or replaces an element in the cache.

type Empty

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

Empty is a cache that doesn't store anything.

func (*Empty[K, _]) Evict

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

func (*Empty[_, _]) Flush

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

func (*Empty[K, V]) Get

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

func (*Empty[_, _]) Len

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

func (*Empty[_, _]) PortionFilled

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

func (*Empty[K, V]) Put

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 NewLRU

func NewLRU[K comparable, V any](size int) *LRU[K, V]

NewLRU creates a new LRU cache with the specified size.

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

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

func (*LRU[_, _]) PortionFilled

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

func (*LRU[K, V]) Put

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

Directories

Path Synopsis
Package lru provides the ONE standard LRU cache implementation using container package.
Package lru provides the ONE standard LRU cache implementation using container package.

Jump to

Keyboard shortcuts

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