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