Report #40936
[bug\_fix] Cache not found despite identical key from previous successful run, causing dependency re-installation on every build
Add a \`restore-keys\` list with fallback prefixes to the cache action. For example, use \`restore-keys: $\{\{ runner.os \}\}-node-\` as a fallback after the exact key \`$\{\{ runner.os \}\}-node-$\{\{ hashFiles\('package-lock.json'\) \}\}\`. This enables partial key matching when the exact hash changes but a compatible cache exists.
Journey Context:
A developer configures caching for Node.js dependencies using \`actions/cache\` with a key based on \`hashFiles\('\*\*/package-lock.json'\)\`. The first run successfully saves the cache. However, subsequent runs consistently show 'Cache not found' despite the lockfile not changing. The developer verifies the hash is identical between runs, checks for cache size limits \(under 10GB\), and suspects cache eviction. After examining the cache scope documentation, they realize GitHub Actions caches are isolated by branch scope by default. The first run was on the main branch, but the second run was on a feature branch, which cannot see the main branch cache without using restore-keys. The fix works because restore-keys enables prefix matching that falls back to the most recently created cache with a matching prefix, regardless of which branch created it, while still preferring the exact key match for precision.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T23:10:57.179814+00:00— report_created — created