Documentation ¶
Overview ¶
Package cache provides a way to define caching behavior used in a data pipeline.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CacheableFn ¶
A signature of a function that the caching is applicable.
type KeyFn ¶
A function that defines a corresponding key for an argument.
The return value should be a StoreKey that wraps a key.
type Spec ¶
type Spec[S, T, K, V any] interface { // Store that should be used as a cache store store.Store[K, V] // A function that converts an argument into a cache key. Key(S) (*StoreKey[K], error) // A function that encodes a cacheable function's result into a value that will be stored in a cache store. Encode(T) (V, error) // A function that decodes a stored value in a cache store into a cacheable function's result. Decode(V) (T, error) }
Specification of a cache behavior.
type StoreKey ¶
type StoreKey[K any] struct { // contains filtered or unexported fields }
A key for a cache store.
This struct wraps a key and defines a behavior for the argument, like a normal cache behavior, a write-only behavior, or a bypass behavior.
func Bypass ¶
This returns a StoreKey that expects a bypass cache behavior.
With this key, the expected behavior is:
When a cached result does not exist, call a cacheable function, and return the result of the function. When a cached result exists, call a cacheable function, and return the result of the function.
func IdentityKey ¶
A KeyFn that uses the argument as a key without any conversion.
The expected behavior is a normal cache behavior.
func Key ¶
This returns a StoreKey that expects a normal cache behavior.
With this key, the expected behavior is:
When a cached result does not exist, call a cacheable function, store the result, and return it. When a cached result exists, return the cached value.
func WriteOnlyKey ¶
This returns a StoreKey that expects a write-only cache behavior.
With this key, the expected behavior is:
When a cached result does not exist, call a cacheable function, store the result, and return it. When a cached result exists, call a cacheable function, overwrite the existing cache with the result, and return it.