Documentation
¶
Overview ¶
Package kvstore implements a key-value store.
Index ¶
- func GetFromCacheOrCall[Value any](cache KVStore, volatile bool, key CacheKey, valueFunc func() (*Value, error)) (*Value, error)
- func GetMapFromCacheOrCall[Key comparable, Value any](cache KVStore, volatile bool, key CacheKey, ...) (map[Key]Value, error)
- func GetSliceFromCacheOrCall[Response any](cache KVStore, volatile bool, key CacheKey, ...) ([]Response, error)
- type CacheKey
- type KVStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFromCacheOrCall ¶
func GetFromCacheOrCall[Value any](cache KVStore, volatile bool, key CacheKey, valueFunc func() (*Value, error)) (*Value, error)
getFromCacheOrCall fetches the value of `cacheKey` from the cache if it exists, interpreted as a `Value`. If it does not exist, it calls `valueFunc` to get the value, and caches it before returning it. If `volatile` is true, `valueFunc` is always called, and the result is not cached.
func GetMapFromCacheOrCall ¶ added in v0.3.0
Types ¶
type CacheKey ¶
type CacheKey []byte
A key in the KVStore.
func GenerateCacheKey ¶
type KVStore ¶
type KVStore interface {
Has(key []byte) (bool, error)
Get(key []byte) ([]byte, error)
Put(key []byte, value []byte) error
Close() error
}
A key-value store. Additional method-like functions that give a typed interface to the store (i.e. with typed values/keys instead of []byte) are provided below, taking KVStore as the first argument so they can use generics.
func OpenKVStore ¶
func OpenKVStore(logger *log.Logger, path string, metrics *metrics.AnalysisMetrics) (KVStore, error)
Initializes a new KVStore backed by a database at `path`, or opens an existing one. `metrics` can be `nil`, in which case no metrics are emitted during operation.