cache

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cache provides an opt-in on-disk cache for compiler outputs keyed by source content + compiler version. Phase A caches the diagnostics slice returned by `kukicha check` so unchanged trees re-check near-instantaneously.

Enablement is opt-in via the KUKICHA_CACHE environment variable (set to "1"). Location defaults to $XDG_CACHE_HOME/kukicha/v1/ and can be overridden via KUKICHA_CACHE_DIR.

Index

Constants

View Source
const FormatVersion = 1

FormatVersion bumps whenever the on-disk cache payload shape changes. Bumping it invalidates every existing cache entry on the next lookup.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a content-addressed disk cache. A zero or disabled Cache is safe to use; Get always misses and Put is a no-op.

func Open

func Open() (*Cache, error)

Open returns a Cache rooted at the user's cache dir (honoring KUKICHA_CACHE_DIR if set). If KUKICHA_CACHE is not "1" the returned Cache reports Enabled()==false and is a no-op for Get/Put.

func (*Cache) Debug

func (c *Cache) Debug() bool

Debug reports whether to emit cache hit/miss traces.

func (*Cache) Enabled

func (c *Cache) Enabled() bool

Enabled reports whether Get/Put will do real work.

func (*Cache) Get

func (c *Cache) Get(key string, out any) bool

Get tries to load a cached value for key into out (which must be a JSON-unmarshallable pointer). Returns true on hit, false on miss. Stale/corrupt entries are treated as misses; callers should not infer correctness from the return value beyond "use out" vs "recompute".

func (*Cache) Key

func (c *Cache) Key(sources map[string][]byte, tag string) string

Key computes a deterministic cache key from sources + tag. sources maps file path to source bytes; paths are sorted before hashing so iteration order doesn't affect the result. The tag distinguishes callers with the same sources but different desired outputs (e.g. "check" vs "build").

func (*Cache) PerFileKey added in v0.7.0

func (c *Cache) PerFileKey(filename string, source []byte, envHash, tag string) string

PerFileKey computes a deterministic cache key for a single-file analysis result, keyed on the file's source bytes plus a hash of the external symbols visible to it (typically semantic.ExportsListHash of the file's dependency siblings). Like Key it incorporates the compiler version and format version so cache upgrades transparently invalidate.

func (*Cache) Put

func (c *Cache) Put(key string, val any) error

Put stores val under key. Writes are atomic (temp file + rename) so a concurrent Get never observes a partially written file.

Jump to

Keyboard shortcuts

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