You cache npm dependencies with primary key 'npm-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}' and restore-keys starting with 'npm-${{ runner.os }}-'. What happens on a lockfile change?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Lockfile hash changes miss the primary key; broader restore-keys can still hydrate a close cache, then the action saves a new primary entry.
Full explanation below image
Full Explanation
actions/cache looks up the primary key first. On miss, it tries restore-keys prefixes for the best partial match. Builds remain correct because package managers reconcile to the lockfile; cache is only an accelerator. Misses do not fail the job by themselves. Caches are not mass-deleted on one key change (though eviction policies apply). restore-keys never rewrite your lockfile. Prefix keys carefully so Windows caches do not restore onto Linux.