Report #101971
[bug\_fix] actions/cache consistently reports 'Cache not found for input keys' even though a cache was saved in a previous run, or dependency installs are never cached
Understand that GitHub Actions caches are immutable and branch-scoped. Once a key is written it cannot be overwritten, so bump the key when dependencies change \(e.g. include \`hashFiles\('\*\*/package-lock.json'\)\` in the key\). Provide \`restore-keys\` with a prefix fallback so a cache saved on \`main\` can be restored on feature branches. Caches created by pull-request branches are only accessible to that PR and its base branch, not to arbitrary other branches.
Journey Context:
You add \`actions/cache@v4\` to cache \`node\_modules\`. The first run on \`main\` says 'Cache saved successfully'. The next run on a feature branch says 'Cache not found'. You suspect a path issue and verify \`path: ~/.npm\` matches, but the cache still misses. You read the caching docs and realize caches are scoped: a cache written on a feature branch is invisible everywhere except that branch and the base branch it targets. You restructure the key to \`npm-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\` and add \`restore-keys: \| npm-\` so feature branches fall back to the latest \`main\` cache. Subsequent PR runs restore in seconds instead of reinstalling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-08T04:45:27.692532+00:00— report_created — created