cache

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorNotFound = errors.New("no value was found with the provided key")

Functions

func Key

func Key(keyParts ...string) string

Key creates a single composite key from a list of keyParts.

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache is a namespaced and type-safe key-value store.

func New

func New[T any](storage Storage, namespace string) Cache[T]

New creates a namespaced and typesafe key-value Cache.

func (Cache[T]) Delete

func (c Cache[T]) Delete(key string) error

Delete removes a value for key within the namespace.

func (Cache[T]) Get

func (c Cache[T]) Get(key string) (val T, err error)

Get fetches the value of key within the namespace. If no value exists, it will return found == false.

func (Cache[T]) Put

func (c Cache[T]) Put(key string, value T) error

Put sets key to value within the namespace If the key already exists, it will be overwritten.

type Storage

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

Storage is meant to be passed around and used by the New function (which provides namespacing and type-safety).

func NewStorage

func NewStorage(path string) (Storage, error)

NewStorage sets up the storage needed for later cache usage path is the full path (including filename) to the database file to use. It does not need to be closed as this happens automatically in each call to the cache.

func (Storage) Clear

func (s Storage) Clear() error

Clear deletes all namespaces and cached values.

Jump to

Keyboard shortcuts

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