Report #11752
[bug\_fix] Cache not found or cache always misses despite lockfile not changing
Ensure the cache key is stable and restore-keys provide a fallback hierarchy. Use \`restore-keys\` with progressively less specific prefixes \(e.g., \`$\{\{ runner.os \}\}-node-\` as a fallback to \`$\{\{ runner.os \}\}-node-$\{\{ hashFiles\('package-lock.json'\) \}\}\`\). Ensure the \`path\` matches the dependency manager's cache directory \(e.g., \`~/.npm\` not \`node\_modules\` for npm ci\).
Journey Context:
Developer sets up caching for Node.js using \`actions/cache\` with a key \`$\{\{ runner.os \}\}-node-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`. They notice every single build creates a new cache entry \(visible in the Actions tab under Caches\), but the 'Post job' step always says 'Cache saved successfully', while the 'Restore cache' step always says 'Cache not found'. They spend hours verifying that package-lock.json is not changing between runs. They try using \`actions/setup-node\` with \`cache: 'npm'\` \(which handles keys internally\) but get the same result. Finally, they enable step debug logging by setting the \`ACTIONS\_STEP\_DEBUG\` secret to \`true\` and see that the hash is indeed stable, but they are missing \`restore-keys\`. They realize that without \`restore-keys\`, a new branch with a different lockfile hash will never find the main branch's cache. They add \`restore-keys: $\{\{ runner.os \}\}-node-\` and the cache hits immediately on subsequent runs, drastically reducing build time.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:14:12.580394+00:00— report_created — created