Skip to content
Latchkey

How to Migrate Cache Config to GitHub Actions

Every CI cache reduces to a path and a key; in Actions that is actions/cache with a key built from a lockfile hash plus restore-keys for partial hits.

Whatever your old tool cached, the Actions form is the same: pick the install directory as path, key it on hashFiles(<lockfile>), and add restore-keys so a near-miss still restores something.

Concept mapping

SourceGitHub Actions
Travis cache.directoriesactions/cache path
CircleCI save_cache/restore_cacheactions/cache step
GitLab cache.key/pathskey / path
Bitbucket named cacheexplicit path + key
fallback cacherestore-keys

After

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

What does not map cleanly

  • Some tools cache automatically between stages; Actions always needs an explicit actions/cache step.
  • Cache the install directory you can rebuild, not source you need fresh each run.
  • A key with no hashFiles never invalidates; always include the lockfile hash.

Related guides

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