Documentation
¶
Index ¶
- Variables
- type Cache
- type CacheWithResults
- func (c *CacheWithResults[K, V]) GetOrInitialize(ctx context.Context, key K, fn func(context.Context) (V, error)) (Result[K, V], error)
- func (c *CacheWithResults[K, V]) GetOrInitializeValue(ctx context.Context, key K, val V) (Result[K, V], error)
- func (c *CacheWithResults[K, V]) GetOrInitializeWithCallbacks(ctx context.Context, key K, ...) (Result[K, V], error)
- func (c *CacheWithResults[K, V]) ReleaseAll(ctx context.Context) error
- type OnReleaseFunc
- type PostCallFunc
- type Result
- type ValueWithCallbacks
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrCacheRecursiveCall = fmt.Errorf("recursive call detected")
Functions ¶
This section is empty.
Types ¶
type Cache ¶ added in v0.16.3
type Cache[K comparable, V any] interface { // Using the given key, either return an already cached value for that key or initialize // an entry in the cache with the given value for that key. GetOrInitializeValue(context.Context, K, V) (Result[K, V], error) // Using the given key, either return an already cached value for that key or initialize a // new value using the given function. If the function returns an error, the error is returned. GetOrInitialize( context.Context, K, func(context.Context) (V, error), ) (Result[K, V], error) // Using the given key, either return an already cached value for that key or initialize a // new value using the given function. If the function returns an error, the error is returned. // The function returns a ValueWithCallbacks struct that contains the value and optionally // any additional callbacks for various parts of the cache lifecycle. GetOrInitializeWithCallbacks( context.Context, K, func(context.Context) (*ValueWithCallbacks[V], error), ) (Result[K, V], error) }
func NewCache ¶ added in v0.16.3
func NewCache[K comparable, V any]() Cache[K, V]
type CacheWithResults ¶ added in v0.16.3
type CacheWithResults[K comparable, V any] struct { // contains filtered or unexported fields }
func NewCacheWithResults ¶ added in v0.16.3
func NewCacheWithResults[K comparable, V any](baseCache Cache[K, V]) *CacheWithResults[K, V]
func (*CacheWithResults[K, V]) GetOrInitialize ¶ added in v0.16.3
func (*CacheWithResults[K, V]) GetOrInitializeValue ¶ added in v0.16.3
func (c *CacheWithResults[K, V]) GetOrInitializeValue( ctx context.Context, key K, val V, ) (Result[K, V], error)
func (*CacheWithResults[K, V]) GetOrInitializeWithCallbacks ¶ added in v0.16.3
func (c *CacheWithResults[K, V]) GetOrInitializeWithCallbacks( ctx context.Context, key K, fn func(context.Context) (*ValueWithCallbacks[V], error), ) (Result[K, V], error)
func (*CacheWithResults[K, V]) ReleaseAll ¶ added in v0.16.3
func (c *CacheWithResults[K, V]) ReleaseAll(ctx context.Context) error
type OnReleaseFunc ¶ added in v0.16.3
type PostCallFunc ¶ added in v0.16.3
type ValueWithCallbacks ¶ added in v0.16.3
type ValueWithCallbacks[V any] struct { // The actual value to cache Value V // If set, a function that should be called whenever the value is returned from the cache (whether newly initialized or not) PostCall PostCallFunc // If set, this function will be called when a result is removed from the cache OnRelease OnReleaseFunc }
Click to show internal directories.
Click to hide internal directories.