cache

package
v28.11.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2025 License: Apache-2.0 Imports: 9 Imported by: 1 module, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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, options ...StorageOption) (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.

type StorageOption added in v28.1.0

type StorageOption func(*Storage)

StorageOptions configures the cache storage.

func WithVersion added in v28.1.0

func WithVersion(version string) StorageOption

WithVersion sets a version for the storage. Version is used as prefix for any cached value.

Jump to

Keyboard shortcuts

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