cache

package
v0.0.38 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheEntry

type CacheEntry struct {
	Version string          `json:"version"`
	Data    json.RawMessage `json:"data"`
}

CacheEntry wraps a cached value with a version key for invalidation.

type FileCache

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

FileCache provides a file-based cache using os.UserCacheDir for OS-agnostic storage. Each entry is a JSON file keyed by a hash of the cache key.

func NewFileCache

func NewFileCache(subDirs ...string) (*FileCache, error)

NewFileCache creates a new file cache in the given subdirectory under os.UserCacheDir. For example, NewFileCache("allbctl", "languages") uses ~/.cache/allbctl/languages/ on Linux.

func NewFileCacheInDir

func NewFileCacheInDir(dir string) (*FileCache, error)

NewFileCacheInDir creates a file cache in an explicit directory. Useful for testing.

func (*FileCache) Dir

func (c *FileCache) Dir() string

Dir returns the cache directory path.

func (*FileCache) Get

func (c *FileCache) Get(key, version string) (json.RawMessage, bool)

Get retrieves a cached value. Returns the data and true if a valid entry exists with a matching version; otherwise returns nil and false.

func (*FileCache) Set

func (c *FileCache) Set(key, version string, data interface{}) error

Set stores a value in the cache with the given version key.

Jump to

Keyboard shortcuts

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