cache

package
v0.0.45 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 6 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 io.Closer] struct {
	// contains filtered or unexported fields
}

Cache is a cache of elements.

func New

func New[K Hasher, V io.Closer](create CreationFunc[K, V], equals EqualsFunc[K], lg log.Interface) *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(ctx context.Context, k K) (*Element[K, V], error)

Get returns the element with given key.

type CreationFunc

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

CreationFunc creates a new value for the given key.

type Element

type Element[K Hasher, V io.Closer] 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. It is safe to call this 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() V

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 the interface satisfied by an object with a hash method.

Jump to

Keyboard shortcuts

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