Report #80536
[bug\_fix] Cache never hits \(0% hit rate\) because cache key includes github.sha or other dynamic commit identifier
Use hashFiles\('\*\*/package-lock.json'\) or similar stable dependency hash for the primary key, use restore-keys for prefix matching, and never use github.sha in the cache key
Journey Context:
Developer adds actions/cache to optimize Node.js build duration. Sets key: $\{\{ runner.os \}\}-build-$\{\{ github.sha \}\} thinking each commit needs its own cached build output. First run uploads cache successfully. Second push triggers workflow, cache step reports 'Cache not found'. Developer checks Actions > Caches tab, sees new cache entry was created with a different SHA hash. Realizes cache entries are immutable and SHA changes every commit, so exact key match is impossible. Attempts to use restore-keys with prefix $\{\{ runner.os \}\}-build- but still rebuilds everything because the primary key is always unique. Finally learns to cache node\_modules using key: $\{\{ runner.os \}\}-node-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\} with restore-keys: $\{\{ runner.os \}\}-node-. Cache hits properly when lockfile unchanged.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:46:55.115982+00:00— report_created — created