How do `actions/cache/restore` and `actions/cache/save` help?
AdvancedConceptCaching, Artifacts, Runners & ARC
Answer
They split the combined action so you control when and what is saved:
- uses: actions/cache/restore@v4
id: restore
with:
path: .turbo
key: turbo-${{ github.ref_name }}-${{ github.sha }}
restore-keys: turbo-${{ github.ref_name }}-
- run: npx turbo run build
- if: github.ref == 'refs/heads/main'
uses: actions/cache/save@v4
with:
path: .turbo
key: ${{ steps.restore.outputs.cache-primary-key }}
Typical uses: save only on main to limit cache churn, save even when tests fail, or save a cache built in a matrix leg only once.
More on Caching, Artifacts, Runners & ARC
How does `actions/cache` match keys and restore keys?IntermediateWhich 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 you cache Docker layers in GitHub Actions?Intermediate