Devii · DevOps · 2026-03-25 · 6 min read

Share

CI Caching: Dependencies, Compiler Outputs, And Invalidation Rules

How GitHub Actions, GitLab CI, and others cache layers; what to cache and what to rebuild clean.

Continuous integration spends much of its time downloading dependencies and recompiling unchanged code. **Caching** restores directories between jobs keyed by lockfile hashes or compiler inputs.

Cache `node_modules` or pnpm store paths keyed on `pnpm-lock.yaml`. Cache Maven `.m2`, Gradle caches, Docker layer caches via buildx. Invalidate when lockfiles change.

Build time trends
Build time trends

Do not cache secrets or ephemeral test databases. Do not cache artifacts that must be reproducible from source without understanding staleness risk.

Measure wall-clock before and after; caches that grow unbounded slow restores. Set retention policies your platform documents.

CI Caching: Dependencies, Compiler Outputs, And Invalidation Rules | AppHost