cachekvstore

package
v11.1.4-modfix Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package cachekvstore implements a key-value store that also keeps track of the last update time of the store. It can be used to cache data that is updated periodically.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheKvStore

type CacheKvStore struct {
	// contains filtered or unexported fields
}

CacheKvStore is a Store that stores data in a *kvstore.NamespacedKVStore. It also stores a last updated time, which is unique for all the keys and is updated on each call to `Set`, and can be used to determine if the data is stale.

func NewCacheKvStore

func NewCacheKvStore(kv kvstore.KVStore, namespace string) *CacheKvStore

NewCacheKvStore creates a new CacheKvStore using the provided underlying KVStore and namespace.

func NewCacheKvStoreWithPrefix

func NewCacheKvStoreWithPrefix(kv kvstore.KVStore, namespace, prefix string) *CacheKvStore

NewCacheKvStoreWithPrefix creates a new CacheKvStore using the provided underlying KVStore, namespace and prefix.

func (*CacheKvStore) Delete

func (s *CacheKvStore) Delete(ctx context.Context, key string) error

Delete deletes the value for the given key and it also updates the last updated time.

func (*CacheKvStore) Get

func (s *CacheKvStore) Get(ctx context.Context, key string) (string, bool, error)

Get returns the value for the given key. If no value is present, the second argument is false and the returned error is nil.

func (*CacheKvStore) GetLastUpdated

func (s *CacheKvStore) GetLastUpdated(ctx context.Context) (time.Time, error)

GetLastUpdated returns the last updated time. If the last updated time is not set, it returns a zero time.

func (*CacheKvStore) ListKeys

func (s *CacheKvStore) ListKeys(ctx context.Context) ([]string, error)

ListKeys returns all the keys in the store.

func (*CacheKvStore) Set

func (s *CacheKvStore) Set(ctx context.Context, key string, value any) error

Set sets the value for the given key and updates the last updated time. It uses the marshal method to marshal the value before storing it. This means that the value to store can implement the Marshaler interface to control how it is stored.

func (*CacheKvStore) SetLastUpdated

func (s *CacheKvStore) SetLastUpdated(ctx context.Context) error

SetLastUpdated sets the last updated time to the current time. The last updated time is shared between all the keys for this store.

Jump to

Keyboard shortcuts

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