cache

package
v0.0.0-...-f6334c0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 12 Imported by: 5

README

Gazelle Caching Utilities

This package provides utilities for caching within or across Gazelle invocations.

File based caching is enabled by setting ASPECT_GAZELLE_CACHE to a path (e.g. .cache/aspect-gazelle.cache) for loading+persisting the cache between Gazelle runs.

Usage

Gazelle language implementations can use cache.Get(config.Config) to fetch a cache.Cache implementation for the current invocation. The cache implementation may be a no-op cache if caching is disabled, an in-memory cache that lasts for the duration of the Gazelle invocation, or a file-based cache that persists between Gazelle invocations. Cache invalidation may be handled based on file content hashes, or a more efficient approach such as a watchman based cache that invalidates based on filesystem events.

Setup

The cache.NewConfigurer() Gazelle config.Configurer must be added to your Gazelle setup. This is done by the Aspect runner automatically, otherwise must be patched into Gazelle or manually added another way.

The primary utility is a file-based cache that can be used to store and retrieve arbitrary data associated with specific keys. The cache is designed to be efficient and easy to use, with support for automatic serialization and deserialization of data.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConfigurer

func NewConfigurer() config.Configurer

func SetCacheFactory

func SetCacheFactory(c CacheFactory)

func VerifyCacheVersion

func VerifyCacheVersion(decoder *gob.Decoder, expectedType, file string) bool

func WriteCacheVersion

func WriteCacheVersion(encoder *gob.Encoder, cacheType string) error

Types

type Cache

type Cache interface {
	/** Persist any changes to the cache */
	Persist()

	/** Load+Store data computed from file contents.
	 *
	 * If the underlying file has changed since the data was computed, the
	 * loader should return false.
	 *
	 * The file content may or may not be read from disk, depending on the Cache
	 * implementation as well as the cache status.
	 *
	 * The path 'root' is not part of the cache key, but is used to resolve
	 * relative paths in the cache.
	 */
	LoadOrStoreFile(root, path, key string, loader FileCompute) (any, bool, error)
}

func Get

func Get(config *config.Config) Cache

Fetch the shared cache for a given config

func NewDiskCache

func NewDiskCache(cacheFilePath string) Cache

*

  • Cache to disk, keyed by file content hash and `buildinfo.GitCommit`.

type CacheFactory

type CacheFactory = func(c *config.Config) Cache

type FileCompute

type FileCompute = func(path string, content []byte) (any, error)

Jump to

Keyboard shortcuts

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