How does `actions/cache` match keys and restore keys?
IntermediateConceptCaching, Artifacts, Runners & ARC
Answer
On restore it looks for an exact match of key; if none, it tries each restore-keys prefix in order and restores the most recent cache whose key starts with that prefix. On job end (post step), it saves under key only if there was no exact hit. Output cache-hit is true only for an exact match.
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip-${{ runner.os }}-${{ hashFiles('requirements*.txt') }}
restore-keys: |
pip-${{ runner.os }}-
Caches are immutable: the same key is never overwritten. To refresh, change the key.
More on Caching, Artifacts, Runners & ARC
Which caches can a branch restore from?AdvancedWhat are the cache size limits and eviction rules?BeginnerWhen should you use setup-* built-in caching instead of `actions/cache`?BeginnerWhy cache the package manager's download cache rather than `node_modules`?AdvancedHow do `actions/cache/restore` and `actions/cache/save` help?AdvancedHow do you cache Docker layers in GitHub Actions?Intermediate