cache

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: 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[V io.Closer] struct {
	// contains filtered or unexported fields
}

Cache is a cache of elements.

func New

func New[V io.Closer](create CreationFunc[V], lg log.Interface) *Cache[V]

New returns a new cache.

func (*Cache[_]) Close

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

Close closes the cache.

func (*Cache[V]) Get

func (c *Cache[V]) Get(ctx context.Context, k string) (*Element[V], error)

Get returns the element with given key.

func (*Cache[V]) MarkAsStale added in v0.2.8

func (c *Cache[V]) MarkAsStale(k string)

MarkAsStale marks the element with given key as stale. The next call to Get will force the element to be (re)created rather than using any cached copy.

type CreationFunc

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

CreationFunc creates a new value for the given key.

type Element

type Element[V io.Closer] struct {
	// contains filtered or unexported fields
}

Element is an entry in the cache.

func (*Element[V]) Key

func (e *Element[V]) Key() string

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

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

Jump to

Keyboard shortcuts

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