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
| Source | GitHub Actions |
|---|---|
Travis cache.directories | actions/cache path |
CircleCI save_cache/restore_cache | actions/cache step |
GitLab cache.key/paths | key / path |
| Bitbucket named cache | explicit path + key |
| fallback cache | restore-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 ciWhat does not map cleanly
- Some tools cache automatically between stages; Actions always needs an explicit
actions/cachestep. - Cache the install directory you can rebuild, not source you need fresh each run.
- A key with no
hashFilesnever invalidates; always include the lockfile hash.
Related guides
How to Migrate GitLab CI Cache and Artifacts to GitHub ActionsTranslate GitLab CI cache keys and artifacts paths into GitHub Actions using actions/cache and upload-artifac…
CI Concept Mapping to GitHub ActionsA cross-tool mapping of common CI concepts (matrix, cache, artifacts, secrets, services, conditionals, manual…