Report #57469
[bug\_fix] Cache not found for input keys or cache saved but never restored despite identical keys in subsequent runs
Use \`restore-keys\` with a partial prefix match \(e.g., \`Linux-npm-\`\) to allow cache restoration when the exact key misses due to file changes, and ensure the \`path\` matches exactly between save and restore \(including glob resolution\). Root cause: \`actions/cache\` requires an exact key match by default; dynamic keys containing \`hashFiles\(\)\` change when dependency files update, causing exact key misses. Without \`restore-keys\`, the cache action performs a cold save. Additionally, if the \`path\` points to different directories or uses non-recursive globs incorrectly, the cache saves empty archives.
Journey Context:
Developer maintains a Node.js monorepo and notices that CI install steps take 15 minutes every run despite using \`actions/cache@v3\`. Checking the logs, they see 'Cache not found for input keys: Linux-npm-abc123...'. They verify the previous successful run saved a cache with a different hash \(e.g., 'Linux-npm-xyz789...'\) because \`package-lock.json\` changed slightly in the new PR. They assumed the cache action would intelligently find the 'closest' match automatically. After searching the \`actions/cache\` documentation, they learn that exact key matches are required unless \`restore-keys\` is specified. They add a \`restore-keys\` block with \`Linux-npm-\` as a prefix. On the next run, the exact key misses \(because package-lock changed\), but the \`restore-keys\` matches the previous cache entry, restoring \`node\_modules\` instantly. The \`npm ci\` command then only installs the delta of changed packages, cutting the time to 2 minutes. The fix works because \`restore-keys\` enables prefix matching, allowing the cache action to find and restore the most recent cache entry that shares the same prefix, even when the exact hash differs, while the \`path\` consistency ensures the restored files land in the correct location for the package manager.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T02:56:59.178178+00:00— report_created — created