kvstore

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

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

func GetMapFromCacheOrCall[Key comparable, Value any](cache KVStore, volatile bool, key CacheKey, valueFunc func() (map[Key]Value, error)) (map[Key]Value, error)

func GetSliceFromCacheOrCall

func GetSliceFromCacheOrCall[Response any](cache KVStore, volatile bool, key CacheKey, valueFunc func() ([]Response, error)) ([]Response, error)

Like getFromCacheOrCall, but for slice-typed return values.

Types

type CacheKey

type CacheKey []byte

A key in the KVStore.

func GenerateCacheKey

func GenerateCacheKey(methodName string, params ...interface{}) CacheKey

func (CacheKey) Pretty

func (cacheKey CacheKey) Pretty() string

Pretty() returns a pretty-printed, human-readable version of the cache key. It tries to interpret it as CBOR and returns the pretty-printed struct, otherwise it returns the key's raw bytes as hex. Intended only for debugging. Not guaranteed to be a stable representation.

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.

Jump to

Keyboard shortcuts

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