# A guide to GitHub Actions caching

Every way to cache in GitHub Actions: actions/cache, setup actions, Docker layers, tool caches, and faster backends, with YAML for each.

[All posts](https://avrea.com/blog)

[Blog](https://avrea.com/blog)
[CI/CD](https://avrea.com/category/ci-cd)

Every way to cache in GitHub Actions: actions/cache, setup actions, Docker layers, tool caches, and faster backends, with YAML for each.

[Tatu Mäkijärvi](https://avrea.com/team/tatu-makijarvi)
1 September 2026

A guide to GitHub Actions caching

There are multiple ways to cache in GitHub Actions: the `actions/cache` action, the caching built into setup actions, Docker layer cache exports, remote caches native to your build tools, persistent disks on self-hosted runners, and co-located cache backends from third-party runner providers. Which methods you need depends on what state your build recreates every run, and the biggest wins come from state the GitHub Actions cache alone doesn't cover.

For repeatable work, caching is often the highest-leverage speedup in GitHub Actions. In our published benchmarks, faster hardware alone is worth 2 to 3x on cold builds, while a Next.js monorepo with Turborepo goes [from 3m 23s on GitHub Actions to 1.4 seconds with a warm Turborepo cache on Avrea, 142x faster](https://avrea.com/blog/nextjs-turborepo-ci-benchmark), and [the Linux kernel build drops from 27m 23s on a standard GitHub runner to 24.1 seconds warm with ccache on Avrea](https://avrea.com/blog/linux-kernel-ci-benchmark), a 68.2x difference. Most workflows collect a fraction of that, because they use the GitHub Actions cache for one dependency directory and nothing else.

On GitHub-hosted ephemeral runners, anything you don’t restore, fetch from a mirror, or get from the runner image starts cold: Docker layers, compiler output, task results, package downloads, Git LFS objects.

The larger multipliers are reachable only when the workload has stable, content-addressable work to reuse, and each kind of work has its own method. For each method, this guide shows what it caches, the YAML to configure it, its limits, and how it combines with the others.

## The `actions/cache` action

[`actions/cache`](https://github.com/actions/cache) gives you explicit control over the GitHub Actions cache: you name paths and a key, it tars the paths into a compressed archive, and ships the archive to a cache service: GitHub’s own, backed by GitHub-owned cloud storage, or your runner provider’s co-located one. Restores run through the cache service API, one call for a signed URL and a second for the download. [In our benchmark](https://avrea.com/blog/how-we-made-github-actions-cache-up-to-6x-faster), a 1 GB restore averaged 73 MB/s and 14.1 seconds end to end, with a 4 to 6x spread between the fastest and slowest run; on Avrea’s co-located cache the same restore takes 2.89 seconds.

```
- uses: actions/cache@v5
  with:
    path: ~/.cache/pip
    key: pip-${{ runner.os }}-${{ hashFiles('requirements.lock') }}
    restore-keys: |
      pip-${{ runner.os }}-
```

The `cache-hit` output is `true` only for an exact primary-key match. A partial-key match or a `restore-keys` fallback can still restore useful files. In this example, an accessible cache starting with `pip-Linux-` can supply previously downloaded packages after a lockfile change; the install resolves the new requirements. When save and restore need to happen at different points in a job, `actions/cache/restore` and `actions/cache/save` split the two halves.

Hash the lockfile, not the source tree; a source-tree hash changes on nearly every commit, so nearly every run misses. Keep `runner.os` in the key, because an archive built on one OS restores broken paths and permissions on another, and give matrix jobs their matrix axis in the key for the same reason.

A run can restore caches from its own branch or the default branch, and a pull request can read its base branch; sibling branches never share.

On Avrea runners the same `actions/cache` steps (v4 and later) work unchanged; requests route to a cache proxy on the runner’s local network instead, up to 6x faster across cache sizes with a much tighter spread between runs.

## Caching built into the setup actions

Language setup actions can manage dependency caching for you, but their defaults differ. [`setup-node`](https://github.com/actions/setup-node) can enable npm caching automatically when `package.json` identifies npm as its package manager; use `package-manager-cache: false` to disable that automatic behavior. `setup-node` takes `cache: npm`, `yarn`, or `pnpm`, and `setup-python` takes `pip`, `pipenv`, or `poetry`. `setup-java` covers Maven, Gradle, and sbt, `setup-dotnet` caches NuGet against a lock file, `ruby/setup-ruby` has `bundler-cache: true`, and `setup-go` enables caching by default for modules and build outputs.

```
- uses: actions/setup-node@v7
  with:
    node-version: 22
    cache: npm
```

The setup action chooses the paths and includes dependency manifests or lockfiles in its cache key. Its maintainers keep those paths current as runner images change, so for standard dependency caching it is usually better than hand-rolled keys. Check what that action stores: `setup-node` saves downloaded packages, not `node_modules`, so you still run the install. [`ruby/setup-ruby`](https://github.com/ruby/setup-ruby#caching-bundle-install-automatically) with `bundler-cache: true` instead runs Bundler and caches installed gems, including compiled extensions. A dependency cache does not necessarily contain your application’s build output.

The same setup-action options work on Avrea. Its package proxies are pre-configured for most supported package managers and can also serve packages when an archive misses. Packages already held by the proxy come from nearby storage; a package it has not seen still needs an upstream fetch. Check the [package-cache setup](https://docs.avrea.com/cache/packages/overview/) for your package manager and any registry overrides in the workflow.

## Docker layer caching, four ways

BuildKit can export a build’s layer cache and import it during a later build. The choice that matters is which [cache backend](https://docs.docker.com/build/cache/backends/) stores those layers.

- **`type=gha`** stores layers in the GitHub Actions cache service. Configuration is minimal, but it inherits the transfer speeds above, one `mode=max` multi-stage build can crowd everything else out of the repo’s quota, and the cache API throttles busy builds; [Docker’s docs](https://docs.docker.com/build/cache/backends/gha/) recommend passing a GitHub token (`ghtoken`) so lookups use the regular API instead. `scope` defaults to `buildkit`, so if you build several images, give each its own scope or they overwrite one another’s cache.
- **`type=registry`** pushes the cache as a separate image to a container registry. `mode=max` keeps intermediate layers; you pay in registry storage and pull time.
- **`type=inline`** embeds cache metadata in the image itself. It supports `mode=min`; use a `mode=max` backend when you need to export intermediate-stage cache records too.
- **`type=local`** writes to a directory, usually wrapped in `actions/cache`, which stacks both methods’ costs.

```
- uses: docker/build-push-action@v7
  with:
    cache-from: type=gha
    cache-to: type=gha,mode=max
```

`RUN --mount=type=cache` mounts (apt lists, cargo registries, Go module downloads) live on the builder’s local disk and vanish with an ephemeral runner unless something persists them. Teams also try `docker save` into `actions/cache`; the image tarball usually gets big enough that restoring and loading it costs about what the pull did.

With Avrea the same flags point at the co-located service instead: `type=gha,url_v2=https://cache.avrea.com/`. Unchanged layers restore rather than rebuilding, and the layer cache no longer competes with your dependency archives for space. The exact configuration is in [Avrea’s Docker cache docs](https://docs.avrea.com/cache/build-cache/docker/).

## Remote caches your build tools bring

Compilers and task runners have had caching longer than CI has: ccache and sccache memoize compilations, Gradle, Turborepo, and Nx reuse task outputs, Bazel and Nix hash whole artifact graphs. Each supports a remote backend, `--remote_cache` for Bazel, a cache node for Gradle, `SCCACHE_BUCKET` for sccache, Vercel’s API or a self-hosted one for Turborepo.

These caches want per-artifact lookups. Tar the whole directory through `actions/cache` and you restore gigabytes to check a few hashes, which is why that pairing disappoints on large projects. A native remote backend fixes that and adds operational work: it’s another service, and its storage and eviction become someone’s job.

Avrea provides [build-cache integrations](https://docs.avrea.com/cache/build-cache/overview/) for Bazel, ccache, Docker, Go, Gradle, Maven, Nix, Nx, sccache, Tuist, Turborepo and Xcode. Setup differs by tool: Gradle needs build caching enabled, Docker needs its backend configuration and Tuist is opt-in. The kernel numbers at the top of this guide use ccache; cold on the same Avrea hardware, that build still takes just over nine minutes.

On macOS, [Xcode compilation caching](https://docs.avrea.com/cache/build-cache/xcode/) reuses Swift and Clang compiler outputs. [Tuist’s module cache](https://docs.avrea.com/cache/build-cache/tuist/) substitutes prebuilt frameworks for eligible targets. Neither is an archive of the entire DerivedData directory. The [iOS and macOS benchmark](https://avrea.com/blog/ios-macos-ci-benchmark) separates these layers and reports which ones each build used.

## Self-hosted runners: caching by owning the disk

On a [self-hosted runner](https://avrea.com/blog/github-actions-runners) that reuses its disk, Docker layers, toolchains and package stores can survive between jobs. An ephemeral self-hosted VM or pod needs an explicit persistent volume or remote cache to retain that state. Some teams also run a registry mirror such as Artifactory or Verdaccio near the runners.

Reusing a disk also means managing cleanup, access to files left by earlier jobs and a wider poisoning surface, because nothing wipes the machine between runs. Avrea keeps cache data between jobs while each job runs in a fresh ephemeral VM. Its [persistent disks](https://docs.avrea.com/persistent-disks/) cost $0.50 per provisioned GB per month, separate from the included repository cache. Jobs receive their own disk copies; by default, only the default branch publishes changes for later jobs.

## Faster cache backends

Co-located caching means the runner reads cache storage from the same machines or the same local network, so restores never cross the public internet. Most third-party runner providers build some version of it, in different shapes: Depot around Docker layer storage, Blacksmith with snapshot-cloned sticky disks, Namespace with per-job cache volumes, RunsOn with an S3 bucket in your own AWS account. Our [runner comparisons](https://avrea.com/alternatives) explain how those caching approaches differ in practice.

Transfer speed is only part of the comparison. The other part is coverage: which kinds of build state get a cache at all. Avrea is our product; the numbers below are published and linked, so you can check them.

- **The Actions cache**, drop-in: identical YAML served from the local proxy at 354 MB/s, up to 6x faster than GitHub’s restores with a much tighter spread.
- **Git checkout acceleration**, which preloads the repository from a datacenter-local mirror before `actions/checkout` runs. Enabled per repository, no workflow changes.
- **Build caches** for the tools above, which fetch matching compiler and task outputs without restoring the entire cache as one archive.
- **A package mirror** across nine ecosystems (JavaScript, Python, Go, Rust, JVM, .NET, Ruby, Swift, and Chocolatey on Windows), with npm entries verified against the hash npm itself publishes, and SwiftPM resolving checksummed archives instead of full git clones, 23 seconds down to 11.
- **Git LFS**, so large files stop being re-downloaded each run. GitHub still authorizes every transfer.

Avrea includes 25 GB of cache storage per repository, with additional storage available to purchase. Per-layer setup lives in [the Avrea cache docs](https://docs.avrea.com/cache/overview/). Private Swift package payloads use separate organization storage and do not count toward this repository quota.

Vendor pages, ours included, call this intelligent caching or smart caching. In concrete terms it means each kind of build state gets its own cache layer, pre-configured in the runner, with storage next to the compute.

## Managing GitHub Actions caches

The repository’s Actions tab lists caches under Management, the [REST API](https://docs.github.com/en/rest/actions/cache) exposes the same list and delete operations, and the [GitHub CLI](https://cli.github.com/manual/gh_cache) has them built in:

```
gh cache list
gh cache delete <key>   # or --all
```

Each cache step prints hit or miss in the job log, and `gh cache list` shows entry sizes, enough to spot a key that never matches or one entry crowding the pool. When a cache underperforms, the checks are quick: read the step’s `cache-hit` output, compare restore time against the install or build time it replaces, list entries with `gh cache list --sort last_accessed_at --order asc`, and check that the key carries OS, architecture, toolchain version, and the lockfile hash. If a cache restores successfully but the build stays slow, [compare the install logs with runner metrics](https://avrea.com/blog/github-actions-observability) to see what work remains.

Limits, all per repository: [10 GB of storage by default](https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching) (admins can raise it, and anything above is billed), eviction of entries unaccessed for 7 days, oldest-accessed-first deletion when over quota, and API rate limits of 200 uploads and 1,500 downloads per minute.

Branch scoping is also a security boundary. GitHub’s docs put the first rule plainly: “Don’t store sensitive information in a cache,” because anyone who can open a pull request can read the base branch’s caches. The restriction on which refs may write and restore exists to block cache poisoning, where a low-privilege event plants a malicious cache that a later, more privileged workflow restores and trusts.

On Avrea, caches are isolated per repository, the Actions layer is scoped by Git ref on top, and everything is encrypted in transit and at rest. `avr cache` in [the Avrea CLI](https://docs.avrea.com/cli/) does the same management jobs with JSON output; eviction follows the same shape, LRU over quota plus 7-day expiry.

## Cache hit but the job is still slow

An archive hit means files were restored. Check the next command to see whether those files removed any work. For example, `setup-node` caches the package manager’s store, so `npm ci` still has to create `node_modules` and run applicable install scripts. Compilation and tests remain unless their own caches cover them.

| What the log shows | What to check next |
| --- | --- |
| No archive restored | Check the requested key, cache version and branch access. Confirm that an earlier job saved an entry with compatible paths and compression. |
| An archive restores, but `cache-hit` is not `true` | Inspect the matched key. A fallback restore can be useful even though it is not an exact primary-key hit. |
| Dependencies restore, then compilation runs | Check the compiler or task cache. A package archive does not contain every build output. |
| Docker reports cached layers, but dependency installation repeats | Find the first invalidated layer and inspect its inputs. Cache mounts have a separate lifecycle from exported layers. |
| Build work decreases, but the job takes longer | Include restore, extraction, save and upload time in the comparison. Check whether several steps cache the same files. |

[`actions/cache` documents the exact-match meaning of `cache-hit`](https://github.com/actions/cache#outputs). Do not skip a necessary install or build solely because a fallback archive was found. The restored files still need to be valid inputs to that command.

Compare the same revision with the cache disabled, during the first cache-populating run and during later runs that can reuse it. Keep those results separate. Include a source-only edit and a lockfile edit to see what survives normal development, then compare total job duration across repeated runs.

If the remaining time is outside the build, inspect the [job’s step timings and runner metrics](https://avrea.com/blog/github-actions-observability).

## What not to cache

Some paths make builds slower or leak data when cached:

- Secrets or credentials, anywhere; anyone who can open a pull request can read base-branch caches
- The `.git` directory in a Docker build context: changing Git metadata can invalidate a `COPY` layer even when application files are unchanged. Exclude it with `.dockerignore` unless the build needs it. File modification times alone do not invalidate Docker’s cache; see the [cache invalidation rules](https://docs.docker.com/build/cache/invalidation/).
- Huge high-churn directories where transferring the archive costs more than redoing the work
- OS- or toolchain-dependent output whose key doesn’t carry OS, architecture, and toolchain version
- `node_modules` straight across Node versions; cache the package manager’s store instead

## Which caching method should you use?

Start from where the minutes go:

- Package downloads slow: a setup action, or the package mirror when your runner has one
- Docker builds slow: BuildKit layer cache, `mode=max`, a `scope` per image
- Compile or test tasks slow: the build tool’s native remote cache
- Checkout or LFS slow: sparse checkout, a Git mirror, or an LFS cache
- A later job needs files from this run: artifacts, not caches

| Method | What it caches | Where it lives | Size limit | Reach for it when |
| --- | --- | --- | --- | --- |
| `actions/cache` | Any paths you name | GitHub cache storage | 10 GB/repo pool | Odd state no built-in covers |
| Setup-action `cache:` | Package manager stores | Same pool, managed keys | Same pool | Default for language deps |
| Docker `type=gha` | Image layers | Same pool | Same pool, plus BuildKit rate limits | Container builds, minimal config |
| Docker `type=registry` | Image layers | Your container registry | Registry storage | Multi-stage builds, bigger caches |
| Tool-native remote cache | Compile and task artifacts | A backend you run or rent | Backend-dependent | Monorepos, compiled languages |
| Self-hosted disk | Everything on disk | Your runner | Your disk | You already run the fleet |
| Runner-provider backends | All of the above | Co-located with the runner | Provider quota (Avrea: 25 GB/repo included; more available to purchase) | Drop-in speed, no cache service to run |

## FAQ

**Is the GitHub Actions cache free?** Up to 10 GB per repository, yes. Organization or repository admins can raise the limit, and storage above 10 GB is billed. Entries unused for 7 days are removed regardless of quota.

**How long do GitHub caches last?** Seven days from last access. When a repository exceeds its storage quota, GitHub also deletes caches oldest-access-first. Avrea cache entries unused for more than seven days are eligible for eviction. It includes 25 GB per repository, with additional storage available to purchase, and uses LRU eviction when a repository exceeds its quota.

**Can two branches share a cache in GitHub Actions?** Only downward: a run reads caches from its own branch and the default branch, and pull requests read their base branch. Sibling feature branches never share, so new branches warm up from the default branch’s saves.

**How do I cache Docker builds in GitHub Actions?** Use buildx with `cache-from` and `cache-to` set to the `type=gha` backend, with `mode=max` if you need intermediate layers from multi-stage builds. On GitHub-hosted runners, watch the 10 GB quota and the cache API’s rate limits. Co-located backends take the same configuration pointed at a different URL.

## Compare cold and warm runs

Start with a copy of a build or test job, with deployment and publication steps disabled. Change `runs-on: ubuntu-latest` to `runs-on: avrea-ubuntu-latest` and check the cache setup for its tools. Record an empty-cache run and repeated runs that can reuse the saved state, keeping the revision and commands fixed. A second run is only a warm-cache test if the logs show that the intended cache was populated and reused.

For most workflows the test is one runner-label change; Docker layer caching adds the `url_v2` flag from the Docker section, and some build caches take a few lines of tool config. Pay as you go includes a monthly credit equivalent to 3,000 minutes on 2-vCPU Linux x86 runners; other metered usage draws on the same credit, and [setup steps are on the Avrea speed page](https://avrea.com/ci-runners). Workflow-level tactics beyond caching are in [how to speed up GitHub Actions](https://avrea.com/blog/speed-up-github-actions).

Last updated 19 November 2026

## Explore other articles

- 21 May 2026
How we made GitHub Actions cache up to 6x faster
Read
<https://avrea.com/blog/how-we-made-github-actions-cache-up-to-6x-faster>

- 27 Oct 2026
Warm builds. Introducing Avrea persistent disks
Read
<https://avrea.com/blog/persistent-disks>

- 16 Sept 2026
GitHub Actions observability: understanding why your CI is slow
Read
<https://avrea.com/blog/github-actions-observability>

## Start shipping with Avrea

[Start free](https://console.avrea.com/)
[Talk to an engineer](https://avrea.com/demo)
