Report #76316
[bug\_fix] Cache restores stale dependencies despite package.json changes because cache key is static
Include a hash of the lockfile \(package-lock.json, yarn.lock, etc.\) in the cache key using \`hashFiles\('\*\*/package-lock.json'\)\`. Use a restore-key that matches the static prefix to allow partial cache hits for unchanged dependencies while ensuring new dependencies trigger a fresh cache save.
Journey Context:
A developer adds a new npm package to package.json and pushes. The CI workflow uses \`actions/cache\` with a static key like \`npm-cache-$\{\{ runner.os \}\}\`. The Post Cache step reports 'Cache hit occurred on the primary key, not saving cache.' The build then fails with 'module not found' for the newly added package. The developer checks the cache key and realizes it hasn't changed despite the package.json modification. Investigating the cache action documentation, they learn that cache keys must be unique to the content being cached. By adding \`$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\` to the key, the cache key changes whenever dependencies change, forcing a fresh cache save when the lockfile is modified, while restore-keys allows hitting older caches for performance.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T10:41:21.237422+00:00— report_created — created