Report #97229
[bug\_fix] actions/cache restore reports 'Cache not found' on every run even though dependencies did not change
Use a stable primary key and provide restore-keys fallbacks from most-specific to least-specific. Do not include the branch name as the only key component, and do not expect a cache created on one branch to be found on another. GitHub Actions caches are immutable per key and scoped to the current branch plus the default branch, so a miss occurs when the exact key changes and no fallback prefix is available.
Journey Context:
You add actions/cache@v4 to your Node workflow using key: $\{\{ github.ref \}\}-$\{\{ hashFiles\('package-lock.json'\) \}\}. On main the first run saves a cache, but every PR branch shows 'Cache not found'. You verify the lockfile hash is identical, then wonder if the action is broken. You read the post-job logs and see the save step reports the cache already exists or was saved. You realize the key is prefixed with refs/heads/branch-name, so each branch has its own cache namespace. You change the key to $\{\{ runner.os \}\}-npm-$\{\{ hashFiles\('package-lock.json'\) \}\} and add restore-keys like $\{\{ runner.os \}\}-npm-. The next PR restores the latest matching cache from main because restore-keys perform prefix matching across branches.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T04:45:46.712581+00:00— report_created — created