cache

package
v0.0.40 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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