Report #15162
[bug\_fix] Cache key does not match or "Cache not found" despite previous successful run, causing dependencies to reinstall from scratch every time
Ensure the \`key\` parameter uses identical patterns between restore and save operations; use \`hashFiles\` with committed lock files and correct glob patterns; implement \`restore-keys\` for fallback to partially matching previous caches; verify lock files exist and are committed to the repository
Journey Context:
Developer configures caching for npm using \`actions/cache\` with \`key: $\{\{ runner.os \}\}-npm-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`. They notice that every workflow run shows "Cache not found" and npm ci runs the full install. They check the Post Run actions/cache step and see "Cache saved successfully" with a key ending in a specific hash. On the next run, the Restore step looks for a key with a completely different hash. They realize that package-lock.json is listed in .gitignore and isn't committed to the repository, so the hashFiles returns an empty string or different value each time. After committing package-lock.json, they still see occasional misses when Dependabot updates the lock file. They add \`restore-keys: $\{\{ runner.os \}\}-npm-\` as a fallback, allowing the cache to hit the most recent npm cache even if the exact lock file changed, with npm ci updating only the changed packages rather than reinstalling everything.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T23:19:35.841095+00:00— report_created — created