Report #20747
[bug\_fix] Cache always misses with 0% hit rate despite successful uploads
Change the cache key from dynamic values \(like \`$\{\{ github.sha \}\}\`, \`$\{\{ github.run\_id \}\}\`, or timestamps\) to stable dependency hashes \(e.g., \`$\{\{ runner.os \}\}-npm-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`\). Use \`restore-keys\` with a prefix \(e.g., \`$\{\{ runner.os \}\}-npm-\`\) to enable partial cache hits when exact match fails.
Journey Context:
The developer adds \`actions/cache\` to their Node.js workflow, setting \`key: $\{\{ github.sha \}\}\` thinking it creates a unique cache per commit. They notice every workflow run takes 5 minutes to rebuild dependencies despite 'Cache saved successfully' messages. They check the Actions cache UI and see hundreds of entries, each used exactly once. Realizing the cache key changes on every commit \(since SHA changes\), they understand the cache is useless. They switch to \`key: $\{\{ runner.os \}\}-build-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\` and add \`restore-keys: $\{\{ runner.os \}\}-build-\`. Now commits that don't change dependencies hit the cache, restoring node\_modules in seconds instead of minutes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:14:27.906538+00:00— report_created — created