store

package
v1.82.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpirationStore added in v1.82.0

type ExpirationStore[K comparable, V any] struct {
	Store[K, V]
	Stopped <-chan struct{}
	// contains filtered or unexported fields
}

ExpirationStore is a generic key value store that expires keys after a certain time. It keeps track of which keys are expired separately from the main store.

func NewExpirationStore added in v1.82.0

func NewExpirationStore[K comparable, V any](ctx context.Context, store Store[K, V], keyTTL *time.Duration, keyExpirationCheckInterval *time.Duration) *ExpirationStore[K, V]

NewExpirationStore returns a new ExpirationStore with the given store and expiration time. TODO: Provide functional options if the arguments list continues to grow.

func (*ExpirationStore[K, V]) Remove added in v1.82.0

func (s *ExpirationStore[K, V]) Remove(key K)

Remove removes the given key from the store. If the key does not exist, it does nothing. Removes the expiration key as well.

func (*ExpirationStore[K, V]) Replace added in v1.82.0

func (s *ExpirationStore[K, V]) Replace(items map[K]V)

Replace replaces the contents of the store with the given map and renews key timers.

func (*ExpirationStore[K, V]) Set added in v1.82.0

func (s *ExpirationStore[K, V]) Set(key K, value V)

Set associates the given value with the given key and sets the expiration time.

type Store

type Store[K comparable, V any] interface {
	// Get returns the value associated with the given key. Returns false if key was not found.
	Get(key K) (V, bool)

	// Items returns the store's contents.
	Items() map[K]V

	// Keys returns all the keys in the store.
	Keys() []K

	// Remove removes the given key from the store. If the key does not exist, it does nothing.
	Remove(key K)

	// Replace replaces the contents of the store with the given map.
	Replace(map[K]V)

	// Set associates the given value with the given key. It will overwrite any existing value
	// or create a new entry if the key does not exist.
	Set(key K, value V)
}

Store is a generic key value store. Implementations should be safe for concurrent use. It is basically just a map with a lock.

func New

func New[K comparable, V any]() Store[K, V]

New returns a new store safe for concurrent use.

Jump to

Keyboard shortcuts

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