Caching
heph caches at the granularity of a target. Before running anything it hashes a target's complete inputs into a single digest; if that digest is already in the cache, heph returns the stored output instead of re-running the action. That is a cache hit.
$ heph run //app:server
0.565s · 1 / 1 done · 1 cached · 0 failed
What goes into the hash
Everything a target declares folds into its input hash: its sources, its dependencies' outputs, the tools it uses, its environment, and the target definition itself. Change any of them and the digest changes, so the target re-runs. Leave them all identical and you get the cached bytes — on your laptop or in CI. This is the foundation of reproducibility.
Because outputs are content-addressed by their inputs, a cache hit is provably the exact artifact you would have built. The cache is trustworthy, not a guess.
Fixed-point caching
A target whose inputs equal its outputs reaches a fixed point: re-running it
produces the same digest, so it's a cache hit and never executes again. This is
what makes idempotent codegen (an in_place formatter,
say) free to re-run — once the tree is formatted, the formatter is a no-op hit.
Controlling caching per target
Whether a target caches, and how aggressively, is a property of the
driver that runs it. The exec driver
exposes a cache field — a bool, or a map of {enabled, remote, history} — to
opt a target out or tune retention. See the driver's page for the exact shape.
In-memory cache
Within a single run, heph also keeps results in memory. Size it with the
memCache block in
.hephconfig; capacityBytes: 0 disables it.
Durable cache storage
Between runs, artifacts are stored on disk, compressed with zstd. Small artifacts
(≤ 8 MiB stored, after compression, by default) are kept in the cache database;
larger ones are stored as files under <homeDir>/cache/blobs/. GC reclaims both.
The threshold is tunable with
cache.spillThresholdBytes
in .hephconfig.
Compression needs no configuration. A few artifacts are stored as-is instead:
| Artifact | Stored |
|---|---|
| Outputs heph packs itself | Compressed |
| A tar or cpio output of 1 MiB or more whose payload is already compressed (an OCI image of gzip layers, for example) | As-is |
| Any other tar or cpio output | Compressed |
The output of an uncacheable target, or of --shell | As-is |
heph tool gc and heph tool clean report the space they free on disk, so a
compressed artifact counts its compressed size.
A cache written by an older heph stays readable locally, so upgrading keeps the local cache warm. The remote cache is not: entries an older heph uploaded are not read, and the first builds after the upgrade repopulate it. Older and newer heph versions can share one cache directory or bucket.
Remote shared cache
A remote cache lets multiple machines share build artifacts. When one machine builds a target, its artifacts are pushed to the remote; any other machine with the same inputs pulls them instead of rebuilding.
Configure one or more remote caches in .hephconfig:
caches:
shared:
uri: s3://my-bucket/heph-cache # s3://, gs://, az://, https://, file://
Writes happen on a background task after a local cache write — every writable remote receives the artifacts in parallel. The build's critical path does not wait on the network; heph stays open until all uploads drain.
Reads happen on a local cache miss. heph tries remotes in ascending-latency order; the first cache holding a matching entry is a cache hit. Confirming the hit only costs a small metadata fetch — the output bytes themselves transfer later and lazily, and only for the outputs something actually reads. Latency is measured once per process (or loaded from a persisted file) and refreshed when the cache definitions change.
A failing remote never fails the build — errors are logged once and, after three consecutive failures, that cache is paused with an exponential backoff. It resumes automatically the next time a request to it succeeds.
For the full set of options and supported backends, see
caches in the configuration reference.
For a step-by-step CI walkthrough, see the Remote cache guide.
Filesystem scan cache
heph also remembers the results of workspace file scans — glob expansion, package discovery — across runs, validated against file and directory metadata. Any change to the tree re-scans the affected paths, so edits are always picked up. This is transparent and needs no configuration.
When debugging, rule the scan cache out by setting
HEPH_DEBUG_CACHED_WALKER=0 — every scan then reads the filesystem directly,
with no caching at all.
Reclaiming space
A target's revisions beyond its configured history
count are trimmed automatically at the end of the run that writes the new one —
there's nothing to run for that.
The on-disk cache still grows as inputs change. Garbage-collect everything else that's no longer reachable (removed targets, orphaned entries):
heph tool gc
The cache database
Removing entries leaves free space inside the cache database, cache.db under
the heph home. heph gives that space back to the filesystem on its own: at the
end of a run that removed entries, at most once an hour (sooner when the free
space grows large), for a few seconds at most. There's nothing to configure.
heph tool gc finishes the job as its last step, returning all of the free
space. Its summary ends with the database's size and what the step did.
A cache created by an older heph version doesn't reclaim space on its own until
it has been converted. The first heph tool gc on it does that by rewriting the
whole database once — minutes on a large one, during which other heph
processes' cache writes wait. The conversion is skipped, and the summary says
how much free disk it needs, when the disk lacks room for the copy it makes.
Failure logs
When a target fails, heph keeps its log in its failure slot,
<homeDir>/failures/<target>/log.txt, whichever driver ran it, along with any
failure_out files and the list of fixes an
in_place target wrote back. heph inspect failure <addr> prints where they
are. The next run of that target (or a cache hit on it) clears the slot.
Nothing else removes the slot of a target that is never built again, so
heph tool gc sweeps those too: slots of targets that no longer exist, and
slots older than 7 days. Change the age with --failure-max-age-days; 0
removes every failure slot.
heph tool gc --failure-max-age-days 1
The summary ends with the number of failure logs removed and the space freed.
To deliberately remove cached entries for a specific target selection instead —
every revision, regardless of history, whether or not the target still
exists — use heph tool clean. Targets are selected the same way as for
run: an address, a label followed by a package matcher, or -e '<expr>'.
heph tool clean //cmd/server:bin # one target (that exact variant)
heph tool clean all //cmd/... # every cached target under a subtree
heph tool clean test //cmd/... # every target labelled "test"
heph tool clean all //... # clear the entire local cache
The selection is required — a bare heph tool clean prints help instead of
wiping the cache. all selects a package without naming a label, the same way
it does for query.
Reaching for clean regularly on a target that hasn't changed is usually a
symptom, not a fix — it means the cache is returning something stale, which
points at an under-declared input on that target rather than a cache problem.
Track down the missing input instead of making clean part of your workflow.