intermediate

Build caching

Cache deterministic task outputs with correct inputs, environment keys, lockfile keys, and invalidation rules.

Build caching stores deterministic task outputs keyed by sources, lockfiles, toolchain versions, config files, and environment variables that affect output. Local caches speed laptops; remote caches speed CI.

| Input class | Examples | |-------------|----------| | Source | `src/**`, package manifests | | Toolchain | Node version, compiler flags | | Env | `NODE_ENV`, feature flags baked into bundle |

Nondeterministic tasks (timestamps in bundles, network fetches without pins) should not be cached—or need normalized inputs.

On interviews: cache poisoning concerns, declaring `outputs`, invalidation when env changes, and secrets never entering cache keys or artifacts.

Common pitfalls: incomplete input sets reusing stale builds; caching integration tests with shared DB state; leaking env secrets into cached artifacts.

The trade-off is CI duration versus rigor maintaining correct invalidation.

Checklist:

  • List every input that changes output.
  • Cache only deterministic tasks.
  • Test cache hit and miss paths.
  • Keep secrets out of cache keys and outputs.