Report #16443
[bug\_fix] Cache restore always reports 'Cache not found' despite a successful cache save in the previous workflow run, leading to dependency re-installation on every execution.
Remove dynamic values like '$\{\{ github.run\_id \}\}', timestamps, or commit SHAs from the cache key. Instead, use a stable identifier such as '$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}' to represent the dependency state. Add a 'restore-keys' list with a broad prefix \(e.g., 'npm-$\{\{ runner.os \}\}-'\) to allow partial matching of older caches when the lockfile changes slightly.
Journey Context:
You notice your workflow spends 3 minutes reinstalling npm dependencies every single run, even though you added actions/cache. You check the action logs and see 'Cache not found' on the restore step, but the post-job step reports 'Cache saved successfully'. Looking at the key defined as key: npm-$\{\{ github.run\_id \}\}, you realize each workflow run has a unique ID, so the key changes every time, making restoration impossible. You search GitHub Community forums and find posts explaining that cache keys must be stable identifiers of the dependency state, not the workflow execution. The fix works because hashFiles generates a checksum of your lockfile, which only changes when dependencies actually change, allowing the cache to match across runs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:44:08.741901+00:00— report_created — created