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 ¶
- type CacheKvStore
- func (s *CacheKvStore) Delete(ctx context.Context, key string) error
- func (s *CacheKvStore) Get(ctx context.Context, key string) (string, bool, error)
- func (s *CacheKvStore) GetLastUpdated(ctx context.Context) (time.Time, error)
- func (s *CacheKvStore) ListKeys(ctx context.Context) ([]string, error)
- func (s *CacheKvStore) Set(ctx context.Context, key string, value any) error
- func (s *CacheKvStore) SetLastUpdated(ctx context.Context) error
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 ¶
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 ¶
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 ¶
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.