Documentation
¶
Overview ¶
Package synccache implements a concurrent-safe unbounded cache that evaluates and stores the result of a value loader.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyExists = errors.New("already exists")
ErrAlreadyExists is returned by Cache.Store when a key is already present in the cache.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache is an object which can be used to create singletons stored in a key-value store.
func NewCache ¶
func NewCache[K comparable, V any]() *Cache[K, V]
NewCache creates an empty unbounded Cache.
func (*Cache[K, V]) Load ¶
Load executes loader for key, if a value hasn't already been loaded.
Loader is shared: concurrent callers for the same key wait on a single loader call, and the loader survives any individual caller's cancellation — it is abandoned only once every caller sharing it has gone away. A caller whose own context is still live is never handed someone else's cancellation; it starts a fresh loader instead.