cache

package
v0.1.6-alpha Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const TenantLocal = "local"

TenantLocal is the sentinel tenant used by the local-only runner path (no daemon, no remote). A single developer's machine has no meaningful namespace neighbours to isolate from; pinning to a constant keeps the on-disk layout shape uniform across runner, daemon, and worker so tooling that walks the cache tree doesn't have to special-case "no-tenant" entries.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompileCache

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

CompileCache is the compile-output cache facade. It wraps an ordered list of Stores and treats them as an L1/L2/... chain: Lookup queries each in order and returns the first hit; Store writes to all of them. Missing or corrupted entries in any one store are skipped, not surfaced as errors — a partial layer should not block other layers.

CompileCache owns the "compile" namespace within each underlying store. Pass raw stores from store.FromConfig; the constructor calls .Namespace("compile") on each so on-disk layout becomes <root>/compile/<hh>/<full-hex>/<blob> (and the S3 equivalent under cache/compile/...). Source blobs and manifests live under sibling namespaces owned by other facades.

func NewCompileCache

func NewCompileCache(ctx *compiler.Context, stores []store.Store) *CompileCache

NewCompileCache returns a CompileCache wrapping the given stores, each namespaced under "compile". The caller retains ownership of ctx; CompileCache holds it so it can derive cache keys (which require the compiler's identity and the config's preprocessing mode).

func (*CompileCache) Lookup

func (c *CompileCache) Lookup(inv *compiler.Invocation, tenantID string) (*compiler.InvocationResult, error)

Lookup returns a hit (non-nil result, nil error) if any wrapped store has a complete entry for inv's cache key, or a miss (nil result, nil error) otherwise. On hit the cached output object is written to inv.Output before the result is returned, so the caller's contract with the user — that the output file exists at the requested path — holds whether the compile ran or was replayed.

func (*CompileCache) Store

func (c *CompileCache) Store(inv *compiler.Invocation, res *compiler.InvocationResult, tenantID string) error

Store writes the result of a freshly-completed compile to every wrapped store. The output bytes are taken from res.Output when populated (the executor — LocalExecutor on the daemon-host path, runtimeExecutor on the worker-in-VM path — has already read them via its own ReadOutput, which knows how to resolve in-VM staging paths back to host-side mount points). If res.Output is empty we fall back to reading inv.Output off disk; this covers callers that haven't populated res.Output yet (and the local fast-path, where inv.Output resolves correctly relative to the daemon's cwd anyway).

The fallback's os.ReadFile is the source of a subtle bug on the worker side: inv.Output there is an in-VM path like /out/foo.o that doesn't exist on the host, so ReadFile returns ENOENT, the "tolerate missing" branch leaves output = nil, and the output blob is silently skipped — caches end up with metadata-only entries that report as misses on lookup. Preferring res.Output fixes that without needing to teach Store about the runtime path translation. A missing output is still tolerated (modes that don't produce a single output file simply skip the blob).

type CompileCacheBackend

type CompileCacheBackend interface {
	Lookup(inv *compiler.Invocation, tenantID string) (*compiler.InvocationResult, error)
	Store(inv *compiler.Invocation, res *compiler.InvocationResult, tenantID string) error
}

CompileCacheBackend is the contract CompileCache satisfies. Kept as a same-package assertion target rather than an externally-used interface — callers reach CompileCache through compiler.CacheBackend (the mirror in the consumer package, which exists to break the import cycle that prevents the cache package from being imported here). Naming it CompileCache-specific avoids implying that future sibling facades (SourceStore, ManifestStore) will share this shape — they won't, since they key on raw content digests rather than parsed invocations.

tenantID is an explicit per-call parameter rather than a constructor arg: one CompileCache instance backs every tenant on a shared worker/daemon, but each Lookup/Store binds to one tenant for the duration of that call. See docs/plan/multi-tenant.md "Storage isolation". Callers with no tenant context (the runner-only local fast path) pass "local".

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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