Skip to content
Latchkey

How to Warm Dependency Caches in CI

A cache only helps if it exists. Warming it from main means PRs never pay the cold-install tax.

GitHub Actions caches are scoped: a PR can read caches from its base branch but not from sibling branches. Build the cache on main so every PR inherits it.

Build the cache on the default branch

Run a scheduled or push-triggered job on main that installs dependencies and saves the cache. PRs then restore it.

Use restore-keys for partial hits

A fallback key lets a slightly stale cache restore and update incrementally instead of starting cold.

.github/workflows/ci.yml
- uses: actions/cache@v4
  with:
    path: ~/.npm
    key: npm-${{ hashFiles('package-lock.json') }}
    restore-keys: |
      npm-

Skip the cold start entirely

Warm-pool managed runners (like Latchkey) keep dependency layers hot across jobs, so even the first PR run starts warm instead of provisioning and downloading from scratch.

Key takeaways

  • PRs can only read base-branch caches, so warm main.
  • restore-keys give partial hits instead of cold starts.
  • Warm-pool runners keep caches hot across jobs.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →