kvcache

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 4 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 Hasher, V any] struct {
	// contains filtered or unexported fields
}

Cache is a cache of elements.

func New

func New[K Hasher, V any](create CreationFunc[K, V], isAlive IsAliveFunc[V], close CloseFunc[V], equals EqualsFunc[K]) *Cache[K, V]

New returns a new cache.

func (*Cache[_, _]) Close

func (c *Cache[_, _]) Close() error

Close closes the cache.

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(k K) (*Element[K, V], error)

Get returns the element with given key.

type CloseFunc

type CloseFunc[V any] func(V) error

CloseFunc closes the given value.

type CreationFunc

type CreationFunc[K Hasher, V any] func(context.Context, K) (V, error)

CreationFunc creates a new value for the given key.

type Element

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

Element is an entry in the cache.

func (*Element[K, _]) Key

func (e *Element[K, _]) Key() K

Key returns the key for this element. This can be safely called after a call to Release.

func (*Element[_, _]) Release

func (e *Element[_, _]) Release()

Release decrements the ref count for this element. This must be called once you are finished with this element. It is safe to call Release multiple times.

func (*Element[_, V]) Value

func (e *Element[_, V]) Value(ctx context.Context) (V, error)

Value returns the value for this element. Calling Value after a call to Release will panic.

type EqualsFunc

type EqualsFunc[K Hasher] func(K, K) bool

EqualsFunc returns true iff two keys are equal.

type Hasher

type Hasher interface {
	Hash() uint32
}

Hasher is an object with a Hash method.

type IsAliveFunc

type IsAliveFunc[V any] func(context.Context, V) bool

IsAliveFunc tests whether the given value is alive.

Jump to

Keyboard shortcuts

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