Arezgitfield notes / engineering
Release engineeringUPDATED OCT 28, 2026

Design CI Caches Around Compatibility and Trust

Define who may produce and restore CI cache entries, choose compatible keys, and verify that cache misses or suspicious entries cannot redefine release evidence.

Arezgit Editorial6 min read
AREZGIT / FIELD NOTERELEASE ENGINEERING
A restored CI cache can change the files a build executes before the build has verified them. It can also hide an undeclared dependency that fails on a clean runner. Treat cache design as a
READ / VERIFY / APPLYTECHNICALLY REVIEWED

A restored CI cache can change the files a build executes before the build has verified them. It can also hide an undeclared dependency that fails on a clean runner. Treat cache design as a decision about compatible inputs and trusted producers, with a correct uncached path available for comparison.

Start with the cached path and the jobs allowed to populate it. The example below uses npm package archives and GitHub Actions cache scopes; other CI services require their own producer-access and key-matching review.

Declare exactly what the cache contains

Separate downloaded dependency archives, installed dependency trees, compiler intermediates, generated source, and deployable artifacts. These contents have different compatibility requirements. A dependency archive may be revalidated by an installer, while a restored generated executable may run immediately.

For each cached directory, identify its producer, consumer, validation step, and clean reconstruction command. If nobody can explain how a cache entry is rebuilt from declared inputs, investigate before extending its retention. A cache should save repeat work without becoming the only surviving copy of required release state.

A signed deployment package needs release-artifact identity and retention even if its dependencies came from a disposable cache. Storing that package only in an evictable cache would make cache maintenance a release recovery risk.

Inspect the directory contents through a controlled credential-free fixture. Keep authentication files, local configuration, and private build output outside broadly readable cache paths. The GitHub caching reference warns against storing sensitive information in caches and documents access boundaries that depend on workflow context.

Map who can write and who can restore

Draw the producer-to-consumer relationship for pull requests, trusted branch builds, and release jobs. Determine which triggers can create cache entries and which existing entries they can read. Review the actual platform rules rather than assuming a branch name is an isolation boundary.

Ask what would happen if an untrusted contribution controlled the contents of a restored directory. Could a later trusted job execute a cached binary, load a plugin, or publish generated output? Identify the first place that content gains authority and the validation that precedes it.

Choose separate production paths or cache namespaces when that prevents an unacceptable trust transition. Names alone are not sufficient if the service permits another producer to populate the same destination. Enforce the producer restrictions using the platform's supported controls and verify them with an isolated workflow.

This cache review complements the CI credential guide. A job with minimal credentials can still produce misleading build evidence if it consumes unverified cached state. Restrict both the authority available to the job and the inputs allowed to shape its result.

Design keys around compatibility, then inspect fallbacks

List the inputs that determine whether cached state remains usable: operating system, architecture, runtime or compiler version, dependency lockfile, build mode, and relevant tool configuration. Include the dimensions that change the stored representation instead of adding arbitrary values to make the key look specific.

GitHub's reference describes exact matching and fallback matching through restore keys. A broad fallback can intentionally restore an older dependency cache, but it should not imply that installed output is already compatible. Require the consuming tool to validate or reconstruct the state before using it.

In the synthetic build, an archive cache restored from a related lockfile might still save network downloads while the installer verifies the requested packages. A cached compiled native module from another architecture deserves a different policy. Express that difference in the cached path and validation procedure, not just the key's wording.

Avoid treating a cache hit as permission to skip tests or dependency verification. A hit describes matching behavior under the cache service's rules; it does not establish that the entry satisfies your release contract.

Keep cache misses and corrupted entries recoverable

For a concrete Node.js example, cache downloaded npm package content rather than the installed node_modules tree. Keep the install step on both hits and misses. The npm cache documentation describes integrity checks for cached content; the clean-install command uses the committed dependency description and rejects a mismatched lockfile. Those checks have a specific scope: matching bytes do not establish that a dependency or its lifecycle script is trustworthy.

A synthetic key policy might produce this shape:

npm-archives-v2-linux-x64-node24-LOCKFILE_HASH

LOCKFILE_HASH stands for a digest calculated by the workflow, not a literal shared cache key. The prefix separates this representation from an older cache policy. OS, architecture, and runtime make the intended consumer clear. A restore prefix ending at node24- can deliberately reuse archives from a previous lockfile, but the installer must still resolve and validate the current lockfile. A hit must not skip installation or tests.

Review three outcomes against the same source revision: an exact match, an older-lockfile fallback, and a miss. All three should run the clean installation and application checks. Only download work should differ. If a fallback changes the installed dependency graph, the cache has crossed from optimization into an undeclared input.

GitHub's cache access rules also distinguish ordinary pull-request merge refs from default-branch contexts. A pull_request cache is scoped to its merge ref; a cache produced by a more privileged workflow has a different trust path. Current documented controls include cache-mode: read to restrict a job to restoration. Check the supported service version and reusable-workflow inheritance before adopting that setting. A cache-key prefix is useful organization, but it does not replace enforced write restrictions.

Run the build with an empty cache in an isolated runner. Confirm that all required inputs can be obtained through their approved channels and that the produced artifact passes the same checks. If the clean build needs an undocumented tool or generated file, repair that declaration before optimizing further.

Then inject a harmless malformed fixture into the cache path and verify the failure behavior. The consumer should reject or reconstruct invalid state with an actionable error. Avoid a fallback that silently bypasses integrity checks merely because the cache restoration step succeeded.

Set a bounded recovery procedure for suspected cache contamination. Invalidate the affected namespace or key, rebuild from reviewed inputs, and compare the resulting evidence. Keep prior verified artifacts available through artifact retention so that cache invalidation cannot remove the release recovery path.

Observe cache size, restoration time, and failure frequency using labels that do not contain private dependency names or paths. A large cache that rarely saves work may be increasing complexity without providing useful acceleration.

Review the optimization against a clean baseline

Compare cached and uncached runs using the same source, lockfile, toolchain, and build settings. The required result is agreement on the checks and artifact properties your process claims to verify. Byte equality is appropriate only when the build promises reproducible output under those conditions.

Record which cache differences are tolerated and why. A timestamped generated file may require a build-system change before byte comparisons become meaningful; a different dependency version requires investigation rather than an exception labeled performance.

Keep an uncached run available as a diagnostic control when a new platform or release trigger is added. If only cached runs pass, identify the missing declared input before widening the restore key. If only cached runs fail, invalidate the affected entry and preserve enough sanitized evidence to distinguish an incompatible representation from an untrusted producer.

READER SIGNAL

Was this guide useful?

Your rating helps us prioritize clearer, more practical technical content.

AREZGIT / DESKTOP WORKSPACEFROM FIELD NOTE TO RELEASE

Review diffs, run checks, and prepare the release in Arezgit.

Keep Git review, security scanning, API checks, database inspection, and release preparation together in one local desktop application.

Explore Arezgit