caches

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 5 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] interface {
	Get(ctx.C, K) (V, HitMiss, error)
	Invalidate(ctx.C, K)
}

func Mem

func Mem[K comparable, V any](c ctx.C, miss func(ctx.C, K) (V, error)) Cache[K, V]

func NewLRU

func NewLRU[K comparable, V any](c ctx.C, maxSize int,
	onMiss func(ctx.C, K) (v V, elementSize int, err error),
) Cache[K, V]

type HitMiss

type HitMiss string
const (
	HIT  HitMiss = "hit"
	MISS HitMiss = "miss"
	ERR  HitMiss = "err"
	NO   HitMiss = "no" // no cache
)

type LRU

type LRU[K comparable, V any] struct {
	MaxSize int

	// called when there is a cache miss, allowing the implementation to make room for the new entry
	OnMiss func(c ctx.C, k K) (V, int, error)
	// contains filtered or unexported fields
}

func (*LRU[K, V]) Get

func (this *LRU[K, V]) Get(c ctx.C, k K) (V, HitMiss, error)

func (*LRU[K, V]) Invalidate

func (this *LRU[K, V]) Invalidate(c ctx.C, k K)

func (*LRU[K, V]) Keys

func (this *LRU[K, V]) Keys() []K

func (*LRU[K, V]) String

func (this *LRU[K, V]) String() string

Jump to

Keyboard shortcuts

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