A primary cache key is 'Linux-npm-a1b2c3'. Which restore-keys entry best allows falling back to the most recent Linux npm cache when the exact key misses?
Select an answer to reveal the explanation.
Short Explanation and Infographic
restore-keys use prefix matching. Linux-npm- matches older Linux npm caches when the full hash key misses, while avoiding Windows caches that would be incompatible.
Full explanation below image
Full Explanation
actions/cache looks up the primary key first. On miss, it evaluates restore-keys in order as prefixes and restores the most recently created matching cache. Using Linux-npm- scopes fallback to the same OS and package ecosystem without requiring the exact lockfile hash. Windows-npm- would restore incompatible platform caches. A bare hash without OS prefix is a poor prefix and may not match intended entries. A longer key that does not prefix-match existing entries will not help. Good key design: ordered from most specific primary key to broader restore-keys prefixes. Remember caches are scoped by branch policies and have size limits that can evict older entries.