Skip to content
Latchkey

How to Warm a Cache With a Scheduled Job in GitHub Actions

A scheduled job on main installs dependencies and saves the cache so it never ages out and every branch inherits it.

Caches unused for 7 days are evicted, and default-branch caches seed every branch. A nightly job that runs npm ci and saves the cache keeps it fresh and available, so the first PR of the day gets a warm hit instead of a cold install.

Steps

  • Add on.schedule with a nightly cron.
  • Restore, install, then save the cache under the shared key.
  • Run it on the default branch so all branches inherit the warm cache.

Workflow

.github/workflows/ci.yml
on:
  schedule:
    - cron: '0 4 * * *'
jobs:
  warm:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/cache@v4
        with:
          path: ~/.npm
          key: npm-${{ hashFiles('package-lock.json') }}
      - run: npm ci

Gotchas

  • Scheduled runs use the default branch, which is exactly where a shared cache should live.
  • Latchkey managed runners keep these warm-up jobs cheap and auto-retry transient failures.

Related guides

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