testocache

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package testocache provides persistent caching primitives for plugins.

The cache directory defaults to ".testo_cache" in the test working directory. It can be changed with -cache.dir or TESTO_CACHE_DIR. Caching can be disabled with -cache.disable or TESTO_CACHE_DISABLE.

Package-level functions use the default keyspace. Use Namespace to create an isolated keyspace.

The on-disk format is internal. Writes use a temporary file and os.Rename. Malformed entries are treated as missing. Operations are synchronized within one process; cross-process locking is not provided.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDisabled indicates that caching is disabled.
	ErrDisabled = errors.New("testocache: cache is disabled")

	// ErrInvalidKey indicates that passed key is invalid.
	// Currently, key is invalid if it contains a NUL-byte.
	ErrInvalidKey = errors.New("testocache: invalid key")

	// ErrNotFound indicates that value was not found the passed key.
	ErrNotFound = errors.New("testocache: not found")
)

Functions

func Disabled

func Disabled() bool

Disabled returns true if caching is disabled. It's up to the package user to handle disabled state, e.g. do not save objects in cache when this function returns true.

func Get

func Get(key string) ([]byte, error)

Get cached object by the given key. Key must not contain a NUL-byte. Malformed cache entries or entries with mismatched stored keys are treated as missing.

If cache is disabled (see Disabled), this function returns ErrDisabled.

func Keys

func Keys(pattern string) (keys []string, err error)

Keys returns keys matching pattern using path.Match syntax. Non-cache files in the cache directory are ignored. If cache is disabled (see Disabled), this function returns ErrDisabled.

func Remove

func Remove(key string) error

Remove object from cache by the given key. Key must not contain a NUL-byte. If the key is not present, this function returns ErrNotFound.

If cache is disabled (see Disabled), this function returns ErrDisabled.

func Set

func Set(key string, value []byte) error

Set saves value to cache with the given key. Key must not contain a NUL-byte. Existing values for the same key are replaced.

If cache is disabled (see Disabled), this function returns ErrDisabled.

Types

type Cache added in v1.6.0

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

Cache is a scoped key-value cache.

The zero value uses the package-level cache keyspace. Use Namespace to create one when several plugins or helpers need to share the same cache directory without sharing the same keyspace.

func Namespace added in v1.6.0

func Namespace(name string) Cache

Namespace returns a scoped cache for name.

Namespaces are isolated from each other and from the package-level cache functions. An empty name selects the package-level cache keyspace. Namespace names must follow the same validity rules as cache keys.

func (Cache) Get added in v1.6.0

func (c Cache) Get(key string) ([]byte, error)

Get is like Get but uses c's keyspace.

func (Cache) Keys added in v1.6.0

func (c Cache) Keys(pattern string) (keys []string, err error)

Keys is like Keys but uses c's keyspace.

func (Cache) Remove added in v1.6.0

func (c Cache) Remove(key string) error

Remove is like Remove but uses c's keyspace.

func (Cache) Set added in v1.6.0

func (c Cache) Set(key string, value []byte) error

Set is like Set but uses c's keyspace.

Jump to

Keyboard shortcuts

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