testocache

package
v1.5.1 Latest Latest
Warning

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

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

Documentation

Overview

Package testocache provides caching primitives to be used by external plugins.

By default, it stores cache in a directory "$TWD/.testo_cache", where "$TWD" refers to the "test working directory" (not necessary a project root). Usually, this is a directory where "_test.go" file, which calls this package, is located.

Can be overridden passing "-cache.dir ~/My/Dir" flag to the "go test" command OR (with lesser priority) with environment variable "TESTO_CACHE_DIR".

Caching can also be disabled with flag "-cache.disable" or environtment variable "TESTO_CACHE_DISABLE" (e.g. "=true").

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.

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

func Keys

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

Keys returns all glob-matched keys by the given pattern.

The pattern syntax is:

pattern:
	{ term }
term:
	'*'         matches any sequence of non-/ characters
	'?'         matches any single non-/ character
	'[' [ '^' ] { character-range } ']'
	            character class (must be non-empty)
	c           matches character c (c != '*', '?', '\\', '[')
	'\\' c      matches character c

character-range:
	c           matches character c (c != '\\', '-', ']')
	'\\' c      matches character c
	lo '-' hi   matches character c for lo <= c <= hi

Keys requires pattern to match all of name, not just a substring.

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 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.

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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