A branch switch at midday produces an instant build. The bundle comes out of cache, the terminal prints a green line, and a runtime check later finds a difference that should have been compiled away. The cache did not malfunction. Its key matched, and the key was too small.

What the key is made of

Bazel breaks a build into actions. Each action declares its inputs, output names, command line and environment variables. The remote cache holds two distinct structures. The action cache maps an action hash to result metadata; content-addressed storage, or CAS, holds output files addressed by their own bytes. Over HTTP these live under /ac/ and /cas/, and the keys are SHA256 hashes. Remote caching requires Bazel 0.10.0 or later.

The split matters when reasoning about invalidation. A metadata hit answers that this command ran with these inputs before. A CAS hit answers that these exact output bytes already exist somewhere. One speaks of history, the other of content.

The wrong hit is the expensive one

Only environment variables explicitly whitelisted through --action_env enter an action definition. A variable left outside the whitelist can differ between machines while the action hash stays the same. $PATH is the classic case: two machines with tools in different locations cannot share a hit even with identical source, because the effective environment differs.

The reverse failure is worse. A compiler installed outside the workspace is not tracked as an input. Two different compilers can produce the same action hash and different output. That is a wrong hit, not a low hit rate, and no amount of warming repairs it.

Bazel also warns that inputs can change during a build. An output produced while a source file is being edited can be uploaded as if valid. The flag --experimental_guard_against_concurrent_changes detects that situation. Once a cache is polluted, the remedy is to clear it as a whole: entries are stored by name and hash set, with no way to tell which build an entry came from. Selective cleanup is not available.

Four places an answer can come from

Where the answer livesStructure holding itKeyed byReach
Local action cacheMetadata on the machineHash of the action definitionOne workspace
Disk cache (--disk_cache)Output files on local diskAction hash over a content setCheckouts and branches on one machine
Remote action cache (/ac/)Metadata on the cache serverSHA256 of the actionTeam and CI machines
Remote CAS (/cas/)Output bytes on the cache serverSHA256 of output contentTeam and CI machines

Bazel looks on the local machine before consulting the remote cache. The disk cache set by --disk_cache serves multiple checkouts and branch switches on one machine, while the remote cache is what a team and CI share across machines. Bazel 7.4 adds --experimental_disk_cache_gc_max_size and --experimental_disk_cache_gc_max_age to reclaim idle entries, with a default idle timer of five minutes.

Deliberately wider keys

Turborepo hashes task inputs into a fingerprint and keeps two layers: a global hash and a task hash. A change in either layer means a miss. Tasks are assumed deterministic; a task that yields different outputs from identical inputs makes cache behavior unpredictable. The global hash takes in lockfile changes, root package.json dependencies, the contents of globalDependencies files, globalEnv values and flags that change behavior. When a package consumed by the root changes, every JavaScript task and root task is invalidated. That is intentional. The key grows rather than risk reusing a stale output.

Nx hashes each task separately, so a pipeline can be partly cached. Its inputs include project sources, files in dependent projects, workspace configuration, external dependency versions, runtime values such as operating system and CPU architecture, and command line arguments. A cache entry stores terminal output, files matched by outputs and the task hash; source files are not stored. The Nx documentation states that Nx errs on the side of caution: inputs are better over-included than omitted, because a missing hash factor can reach end users. With no inputs configured, all files of the project and its dependencies are included by default.

When the cache is slower

Turborepo lists cases where hitting the cache costs more than running the task: work that finishes very fast, artifacts so large that upload and download exceed regeneration, such as full container images, and scripts that maintain an internal cache of their own. Whether to disable caching for a task is a project decision. Bazel likewise notes that stdout and stderr are a poor basis for estimating hit rate.

An Nx feature called Ultracache hashes the files a task actually read during a recorded run, so changing a declared but unread file no longer forces invalidation. It has been available since Nx 24.0.0 and depends on Nx Cloud and Workers. These are mechanisms described by the projects themselves, with performance framing left aside.

The part worth keeping

A cache earns trust by being right. Keys need to be wide enough to catch changes in environment, tools and dependencies; local answers come before remote ones; pollution is treated as a whole-cache event. Hit rate describes the state of a cache, but it does not decide whether the cache can be trusted.

Cross Mini App treats cache correctness as a build invariant around the shared runtime.

Sources