Report #83374
[bug\_fix] Cache action reports 'Cache not found for input keys' on every run despite previous successful save, resulting in full dependency installation time with no cache hits
Use a stable, deterministic cache key based on lockfile hashes \(e.g., \`$\{\{ runner.os \}\}-npm-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`\) and provide \`restore-keys\` with partial match patterns \(e.g., \`$\{\{ runner.os \}\}-npm-\`\) to fallback to the most recent cache when exact match fails, avoiding dynamic values like commit SHA or timestamps in the primary key
Journey Context:
Developer notices their Node.js workflow consistently takes 6 minutes to run \`npm ci\` even though they configured \`actions/cache\` with \`key: $\{\{ runner.os \}\}-build-$\{\{ github.sha \}\}\`. The cache step logs show 'Cache not found for input keys' every single run. Developer checks the Actions cache management UI and sees hundreds of saved caches, each 200MB, one for every commit SHA. They realize the key changes on every commit, so it never matches. They try changing to a static key \`npm-cache\` and suddenly it hits, but now when \`package.json\` changes, it still hits the old cache and uses stale dependencies. The rabbit hole leads to GitHub documentation explaining that \`restore-keys\` allows prefix matching. Developer learns that \`hashFiles\` creates a checksum of the lockfile, so the key only changes when dependencies actually change. The fix works because using \`key: $\{\{ runner.os \}\}-npm-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\` creates a deterministic identifier for exact dependency states, while \`restore-keys: $\{\{ runner.os \}\}-npm-\` ensures that even if the lockfile changed \(new exact key\), the job falls back to the most recent cache with that prefix, allowing partial cache hits that save time while \`npm ci\` updates only changed packages.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T22:31:42.257817+00:00— report_created — created