Interview Prep/CI/CD/GitHub Actions

How does caching work with `actions/cache`?

IntermediateConceptGitHub Actions
Answer

actions/cache saves a directory under a key and restores it in later runs. If no exact key matches, it tries restore-keys prefixes (partial hit). Caches are scoped by branch: a PR can read the base branch's cache but not siblings'. The repository has a total cache limit (10 GB by default) and entries unused for 7 days are evicted.

- uses: actions/cache@v4
  with:
    path: ~/.m2/repository
    key: maven-${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
    restore-keys: |
      maven-${{ runner.os }}-

Many setup-* actions (setup-node with cache: npm, setup-java with cache: maven) do this for you.

All CI/CD questions

More on GitHub Actions