cache

package
v0.0.0-...-b47e1f0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ShellOSEnvVar is an environment variable pointing to the
	// directory used for the shell-level cache.
	ShellOSEnvVar = "COMMAND_CLI_CACHE_SHELL_DIR"
	// ShellDataKey is the data key used to store the shell-level cache.
	// Callers should use the `ShellProcessor` and `ShellFromData` functions
	// rather than using this key.
	ShellDataKey = "COMMAND_CLI_CACHE_SHELL"
)

Variables

This section is empty.

Functions

func ShellProcessor

func ShellProcessor() command.Processor

ShellProcessor returns a processor that creates a shell-level `Cache`. This needs to be done at the processor level so we can update an environment variable via `ExecuteData`.

func StubShellCache

func StubShellCache(t *testing.T, c *Cache)

StubShellCache stubs the cache created and set by `ShellProcessor`.

Types

type Cache

type Cache struct {
	// Dir is the location for storing the cache data.
	Dir string
	// contains filtered or unexported fields
}

Cache is a type for caching data in JSON files. It implements the `sourcerer.CLI` interface.

func FromDir

func FromDir(dir string) (*Cache, error)

FromDir returns a cache pointing to the provided directory.

func FromEnvVar

func FromEnvVar(e string) (*Cache, error)

FromEnvVar creates a new cache pointing to the directory specified by the provided environment variable.

func FromEnvVarOrDir

func FromEnvVarOrDir(e, dir string) (*Cache, error)

FromEnvVar creates a new cache pointing to the directory specified by the provided environment variable.

func ShellFromData

func ShellFromData(d *command.Data) *Cache

ShellFromData retrieves the shell-level `Cache` that was set by `ShellProcessor`.

func (*Cache) Changed

func (c *Cache) Changed() bool

Changed returns whether or not the `Cache` object (not cache data) has changed.

func (*Cache) Delete

func (c *Cache) Delete(key string) error

Delete deletes data from the cache.

func (*Cache) Get

func (c *Cache) Get(key string) (string, bool, error)

Get retrieves data from the cache and returns the data (as a string), whether the file exists, and any error encountered.

func (*Cache) GetBytes

func (c *Cache) GetBytes(key string) ([]byte, bool, error)

GetBytes returns data, whether the file exists, and any error encountered.

func (*Cache) GetStruct

func (c *Cache) GetStruct(key string, obj interface{}) (bool, error)

GetStruct retrieves data from the cache and stores it in the provided object. This function returns whether the cache exists and any error encountered.

func (*Cache) List

func (c *Cache) List() ([]string, error)

List lists all cache keys.

func (*Cache) Name

func (c *Cache) Name() string

Name returns the name of the cache CLI.

func (*Cache) Node

func (c *Cache) Node() command.Node

Node returns the `command.Node` for the cache CLI.

func (*Cache) Put

func (c *Cache) Put(key, data string) error

Put puts data in the cache.

func (*Cache) PutStruct

func (c *Cache) PutStruct(key string, i interface{}) error

PutStruct json-deserializes the provided struct and stores the data in the cache.

func (*Cache) Setup

func (c *Cache) Setup() []string

Setup fulfills the `sourcerer.CLI` interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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