Report #38639
[bug\_fix] Cache not found for input keys due to immutable cache keys
Add \`restore-keys\` with a prefix pattern \(e.g., \`$\{\{ runner.os \}\}-npm-\`\) to enable partial key matching. Caches are immutable once created; when the exact hash changes \(due to lockfile modifications\), the lookup fails without fallback keys, causing a cache miss even when similar caches exist.
Journey Context:
You implement dependency caching for your Node.js project using \`actions/cache\` with the key \`$\{\{ runner.os \}\}-node-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`. The first workflow run on the main branch successfully saves the cache. A developer opens a PR updating a single dependency, which modifies package-lock.json. The workflow triggers but logs 'Cache not found for input keys: linux-node-'. You verify in the GitHub UI under Actions > Caches that the previous cache from main still exists with the old hash. You realize that because the lockfile changed, the hash changed, and cache lookups require an exact key match by default. The new cache won't be created until after the job succeeds, but the install step is slow because it starts from scratch. You examine the documentation on cache matching and discover that \`restore-keys\` allows prefix matching. You modify the workflow to include \`restore-keys: \| $\{\{ runner.os \}\}-node-\` before the key. Now, when the exact hash misses, it falls back to the most recent cache with the prefix \`$\{\{ runner.os \}\}-node-\`, restoring the old dependencies. The npm install now only downloads the changed package, cutting the time from 5 minutes to 30 seconds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:20:03.582152+00:00— report_created — created