Architecture
How the compiler wrapper, local store, and daemon divide the work
Keep invoking Kache through kache, including from Cargo's RUSTC_WRAPPER.
V2 ships two executables from the same release:
| Process | Owns |
|---|---|
kache client | Captures each compiler invocation; owns native compiler children, streams, and brokered artifact operations |
Local kache-engine | CLI commands, daemon startup, build-script launchers, and local cache fallback before handoff |
Daemon (kache daemon run, through the engine) | Concurrent cache pipelines, key and restore decisions, remote transfers, and maintenance |
The local daemon is useful without a remote cache. The optional network planner service is a separate process and is not required for exact cache lookups.
The client sends compiler arguments, environment, working directory and IO to the daemon. The daemon runs concurrent cache pipelines, each with its own inputs, jobserver, cancellation and accounting. It does not change its process-wide environment or working directory to serve a client.
On Linux, macOS and Windows, the client starts native compiler children at the daemon's request and applies artifact copies, clones, links, transformed writes, timestamp updates and staged publication. The daemon selects cache entries and restore strategies. The client owns child cleanup and unpublished stages.
All platforms share compiler inputs, workspace operations and the workspace executor. Unix transfers descriptors over private per-invocation sockets. Windows duplicates handles from the authenticated named-pipe peer and retains its native process token, job objects and console. Compiler output and artifact contents travel through pipes or shared file handles, outside control messages.
The engine starts a missing daemon on the first cache-enabled compile. If preparation fails or the client's process restrictions cannot be preserved, the client can run the local engine. The first Commit write attempt transfers execution responsibility to the daemon. A later disconnect fails the invocation.
CLI commands and build-script launchers run in the engine.
Process restrictions
By default, Linux execution delegation requires compatible process credentials, namespaces and security labels, with Seccomp and NoNewPrivs disabled on both peers. Otherwise the client uses its local engine.
On macOS, both peers must be outside Seatbelt sandboxes by default. Peer identity is checked with the kernel audit token. Windows requires matching process-token contexts. Different token generations carrying security attributes require local execution by default, even when both processes belong to the same user.
For a daemon you trust to access the workspace, enable this setting in both the daemon's startup configuration and the build's configuration:
[cache]
trust_daemon_execution = true
KACHE_TRUST_DAEMON_EXECUTION=1 sets the same option. Restart an existing daemon
after changing its startup setting. On Linux this permits the client broker under
Seccomp filters and NoNewPrivs; it does not compare filter programs. On macOS
it permits a sandboxed client or daemon after authenticating the peer. Unknown
sandbox status still requires local execution.
On Windows, this setting permits different TSA://ProcUnique values when both
tokens contain only that known process-identity attribute, or both attribute
lists are empty. Unknown attributes and changes to the attribute's type, flags
or value count still require local execution. User, logon session, groups,
privileges and the other token-context checks still apply. Token attributes can
affect access rules, so enabling this option trusts the daemon to read inputs
under its own token.
Compiler children and brokered restore operations retain the client's restrictions. The daemon still discovers inputs, reads workspace files and maintains cache state under its own restrictions. This setting does not promise to reproduce an arbitrary client sandbox across the whole pipeline. Large-file prestaging is not used by brokered restores.
kache init reports the current execution path after starting the daemon.
kache doctor checks execution eligibility separately from daemon health. This
probe runs no compiler and reserves no worker; each invocation checks admission
again before Commit.
Build path
For an eligible compiler invocation, the pipeline:
- parses the compiler arguments and discovers inputs
- computes a BLAKE3 cache key
- checks the local store: the
[cache.volumes]shard that holds the output directory, if one does, then the main store, then a configured read-only store - asks the daemon for an exact remote result after a local miss
- on a miss, joins a machine-wide flight, takes a memory-weighted permit and a per-key lock, and checks locally again
- runs the compiler if the entry is still absent
- stores outputs as content-addressed blobs
- queues a remote upload when a writable remote is configured
On a machine with no remote, fallback wrapper or read-only store, a unit with no usable input record can start compiling before its key is known. Kache then keys it from the dependency file the compile writes. See Misses without a record.
The second local check prevents duplicate work when another process fills the same key while this process waits for the lock. Hits and passthroughs never join a compile flight. A unit with no usable input record can still wait while another process discovers the same unit's inputs, and a compile that starts before its key is known holds a permit while it runs; either can end as a hit. See Limits.
| Result | Compiler ran | Meaning |
|---|---|---|
local_hit | No | Entry was already in the local store |
prefetch_hit | No | The remote lookup waited on a prefetch download already running for this key |
remote_hit | No | Exact remote lookup downloaded the entry |
miss | Yes | The key and at least one output blob were new |
dup | Yes | The key was new but all output blobs already existed |
error | Yes | The compiler failed; nothing was stored |
skipped | Yes | The compile ran but its result was not stored, for example because a requested output was missing, the compile was faster than cache.min_store_compile_ms, or another process held the key's lock |
passthrough | Not implied | Kache did not cache the invocation: policy declined it, a compiler query ran, another wrapper handled it, or key/store/restore work failed |
An entry that prefetch imported before the compile asked for it logs local_hit. Build timelines mark such units with the prefetch delivery and its timing.
A dup is compiled work. It often means two over-specific keys produced the same bytes.
Local store
The store contains:
index.db, a SQLite index of entries and their blobsstore/blobs/<prefix>/<hash>, the content-addressed output files- entry metadata under
store/<cache-key>/
Identical output bytes share one blob. Restores first try copy-on-write cloning. Unix can use a restricted hardlink fallback for immutable artifacts, and Linux also for proc-macro libraries and build-script binaries. Everything else is copied. Other executables and loadable libraries are never hardlinked because later tools may mutate them.
See Deduplication for platform details.
A miss or a remotely downloaded entry can be stored without waiting for an fsync. The daemon verifies and flushes pending entries on a two-second sweep, up to 64 entries in the main store and in each indexed volume shard. A GC run also flushes pending entries.
Without a reachable daemon, the wrapper attempts to flush the entry it stored. A non-dry-run kache sync also retries pending entries, even when there is nothing to transfer. IO failures or concurrent changes can leave entries pending for the next attempt. While an entry is pending, a hit verifies its blobs against their content hashes; the flush also verifies the bytes before marking that publication durable. Missing or damaged pending artifacts cause a cache miss. Set [cache] deferred_durability = false to flush inside the compile or download instead.
Strict stores validate and flush shared blobs too, before a store or import operation succeeds. This adds a validation read to strict writes. Entries with more than 64 artifact records verify sequentially while holding the store's writer lock to bound open files, so a large flush can delay other writers. Already-durable hits keep the configured restore-verification policy.
Daemon
The daemon owns delegated cache pipelines, remote work and periodic maintenance. For an accepted invocation the client still creates compiler processes and performs brokered restores under its own process restrictions:
- concurrent cache pipelines for delegated compiler invocations
- exact remote checks and downloads
- storing finished C/C++ compiles that wrappers hand over (
cache.daemon_publish) - background uploads and durable upload replay
- background MSVC runtime hashing, with one worker and a bounded queue
- speculative prefetch, and fetching and publishing input records on the remote
- seeding a new checkout's target directory with registry units another checkout built (
cache.seed_new_targets) - copying large executables beside their destinations while the rest of a build runs
- flushing entries stored without an fsync, every two seconds
- scheduled garbage collection
- index upkeep, target-directory cleanup and target-file sharing when the machine is quiet
- monitor statistics that require live transfer state
The client connects through <runtime_dir>/daemon.sock on Unix or a named pipe
on Windows. Before Commit, an unavailable daemon leaves the local engine
responsible for compilation and local caching. Remote work is skipped or
deferred on that path.
See Daemon overview and Lifecycle.
Interception boundary
As RUSTC_WRAPPER, Kache sees rustc and workspace-wrapper invocations, and caches the Clippy ones among them. On Unix, after rustc builds a build script, Kache puts a launcher in its place, so Cargo runs the script through Kache too; see Build scripts. Rust link work driven by rustc can be cached when the artifact policy allows it (cache.cache_executables, on by default on Linux and macOS); an independently invoked linker is outside this path.
On Unix, kache init also adds a shim directory to the front of PATH and sets kache test-runner as Cargo's runner for the host, both through your shell startup files. The cargo shim runs the real Cargo and marks its target directories in use while it runs, so cleanup leaves them alone. It can seed compatible dependency units before Cargo checks a new target. It can also route explicitly opted-in local builds through Blaze. Compiler artifact caching still happens at the wrapper boundary. The rustdoc shim, which init sets as build.rustdoc when that is unset, caches the modes described in Rust documentation. The test runner makes test binaries wait for the compile scheduler's slots.
C/C++ caching is separate. Kache must be invoked as the compiler wrapper (kache cc) or through a compiler-name shim on PATH (kache init --shims, Unix only). Supported object compilations use the same local store and remote pipeline as rustc. clang-cl debug objects stay machine-local. See C and C++.
CUDA goes through kache nvcc (CUDACXX="kache nvcc", NVCC="kache nvcc" or CMAKE_CUDA_COMPILER_LAUNCHER=kache). It caches single-source object compiles in the main store and shares them through the remote. It takes no scheduler permit and does not read volume shards or the read-only store. See CUDA.
Planner
Without a planner service, the daemon prefetches from a ranked list: the identity
manifest for this lockfile, target and profile (or, when none exists, the
manifest of one of the last three committed revisions of Cargo.lock, newest
first), then lockfile shards, then local history, then other keys stored under
the same crate names. That last source needs the daemon to list the remote,
which cache.remote_key_listing turns on; it is on by default only for
filesystem remotes. With cache.planner.endpoint or KACHE_PLANNER_ENDPOINT,
the daemon first asks the preview planner for ranked candidates. A fallback
response returns the client to its local planning path.
The planner does not affect local correctness or exact-key lookup. See Remote service.