Interview Prep/GitHub Actions/Caching, Artifacts, Runners & ARC

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.

All GitHub Actions questions Roadmap: GitHub Actions

More on Caching, Artifacts, Runners & ARC