Run Tests Up to 70% Faster than Traditional Test Grids
HyperExecute Is an AI-Native Test Orchestration Platform to Run Your Automation Test Suites with Blazing Fast Speed.
GitHub Actions Cache: How to Cache Dependencies and Fix Cache Misses
Set up GitHub Actions cache for npm, pip and Maven, build keys that hit, fix cache misses, stay under the 10 GB limit and clear stale caches with gh CLI.
The GitHub Actions cache will store files (e.g. npm, pip or Maven dependencies) between workflow runs so that the jobs don't have to re-download them each time. You can use actions/cache or the cache input of a setup-* action. Each cache is keyed, is scoped to a branch, is capped at 10GB per repository by default and is removed after 7 days of inactivity.
TL;DR
The GitHub Actions cache keeps dependency folders, such as npm's cache, pip's cache or ~/.m2/repository, between workflow runs. Turn it on with the cache input of setup-node, setup-python or setup-java, or with actions/cache and your own key. Each repository gets 10 GB by default, and entries unused for 7 days are deleted.
GitHub Actions Cache Key Rules
- Cache key: Build the GitHub Actions cache key from
runner.osandhashFileson your lockfile, never from a timestamp, run number or commit SHA. - restore-keys: The
restore-keysinput is a prefix fallback that restores the newest close match on a miss;cache-hitthen reports false. - Branch scope: A GitHub Actions run restores caches from its own branch and the default branch, so save the cache on main for a warm start everywhere.
GitHub Cache Options by Tool
- setup-node cache: In GitHub Actions cache npm setups, the
setup-nodeinputcache: 'npm'stores npm's global cache, keyed on the lockfile. Cachesnode_modules: No. - Docker layers: GitHub Actions Docker cache uses the
type=ghaBuildKit backend with Buildx; give each image its own scope so builds do not overwrite each other. - Clear cache: To clear a GitHub Actions cache, delete entries on the repository's Caches page or run
gh cache deletewith a key or--all. - HyperExecute: TestMu AI's HyperExecute caches dependencies by default with YAML 0.2, and
cacheKeypluscacheDirectoriesreplace that default with your own cache.
What Is the GitHub Actions Cache?
The GitHub Actions cache is repository storage for files that don't change very often between runs. A job will restore a cache by key prior to installing anything, and if the job succeeds on a cache miss, then actions/cache will save the listed paths under that key.
In an automation testing pipeline, every test job will have the same set of dependencies and will run once per OS/browser in the matrix. A warm cache reduces the download to a single archive fetch.
Three facts from GitHub's dependency caching reference shape everything else in this guide (as of Nov 2026):
- A cache entry can't be changed. To store new content you have to save it under a new key.
cache-hitis only true in the case of an exact key match. A partial match viarestore-keyswill restore the files but will report no hit.- A run can read caches from its own branch and the default branch. Pull request runs can also read the base branch.
For a quick visual walkthrough of this concept, watch the video below from TestMu AI.
Subscribe to the TestMu AI YouTube channel for more tutorials on testing and automation.
Cache, Artifacts or setup-* Built-In Cache: Which Should You Use?
Use the cache for files you want back on the next run, and artifacts for files you want to keep or inspect after a run. GitHub's docs say the two "cannot be used interchangeably" and warn never to store secrets in a cache.
| Option | What it caches | Who builds the key | Expiry and limits | Best for |
|---|---|---|---|---|
setup-node / setup-python / setup-java with cache: | The package manager's global cache (not node_modules) | The action, from your lockfile | Same cache rules: 7 days unused, 10 GB repo default | Most Node, Python and Java test jobs; one line of YAML |
actions/cache | Any paths you list | You (key, restore-keys) | 7 days unused, evicted oldest-first above the limit | Custom tools, monorepos, build outputs, anything setup-* does not cover |
actions/upload-artifact | Files a job produced (reports, screenshots, traces) | Not keyed; named per run | 90 days by default, retention-days 1 to 90 | Test reports and evidence you download after the run |
| HyperExecute YAML 0.2 caching | Dependencies on HyperExecute machines | HyperExecute by default, or your cacheKey | Managed by HyperExecute | Suites that run their tests on HyperExecute from a GitHub Actions step |
How Do You Cache npm, pip or Maven Dependencies in GitHub Actions?
The fastest way to cache your dependencies is to use the cache input on the language's setup action. It will hash your lockfile into the key for you.
npm (setup-node):
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
cache: 'npm' # also 'yarn' or 'pnpm'
- run: npm cisetup-node caches npm's global cache directory so that npm ci will still run and build node_modules from the local files. The README also states that npm caching is enabled by default when package.json has a packageManager (or devEngines.packageManager) field set to npm and no cache input is specified.
pip (setup-python):
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: '3.13'
cache: 'pip' # also 'pipenv' or 'poetry'
- run: pip install -r requirements.txtCaching is off by default in setup-python, so the cache line is required.
Maven (setup-java):
- uses: actions/checkout@v7
- uses: actions/setup-java@v6
with:
distribution: temurin
java-version: '25'
cache: maven # also 'gradle' or 'sbt'
- run: mvn verifysetup-java stores ~/.m2/repository and keys it on a hash of **/pom.xml and the Maven wrapper files.
Custom paths (actions/cache): use actions/cache if there's no appropriate setup action to cover the tool, or if you need to have control over the key.
- uses: actions/cache@v6
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- run: npm ciHow Do You Cache Docker Image Layers in GitHub Actions?
Docker's GitHub Actions cache backend (type=gha) stores BuildKit layers in the same GitHub Actions cache, so it counts against the same GitHub cache size and usage limits. Set up Buildx first, because the default docker driver cannot export this cache unless the containerd image store is enabled; docker/setup-buildx-action creates a docker-container builder by default. Docker's docs mark the backend as experimental, and every build uses the default buildkit scope, so several images built in one repo overwrite each other's cache unless each sets its own scope (Docker docs, "GitHub Actions cache" backend, as of Nov 2026).
- uses: docker/setup-buildx-action@v4
- name: Build and push
uses: docker/build-push-action@v7
with:
cache-from: type=gha,scope=api
cache-to: type=gha,mode=max,scope=apiNote: Run the same suite in parallel without managing caches. HyperExecute (the AI Test Orchestration platform from TestMu AI) caches dependencies by default with YAML 0.2 and runs from a single GitHub Actions step. Start free on HyperExecute (the Free plan includes 300 minutes of testing on up to 2 concurrent sessions as of Nov 2026).
How Do You Build a GitHub Actions Cache Key That Hits?
A good GitHub Actions cache key only changes when the content you're caching actually needs to change. Build it from the runner OS plus a hash of the lockfile and use a short prefix in restore-keys as a fallback.
GitHub looks for a match in this order:
- An exact match for
keyon the current branch. - A prefix match for
keyon the current branch. - Each
restore-keysentry is in order; the most recently created match wins. - The same three steps on the default branch.

Keep these rules in mind:
- Hash the lockfile, not the package.json.
hashFiles('**/package-lock.json')will change when the resolved versions change. - Put
runner.osin the key. A cache saved onwindows-latestwon't be recoverable onubuntu-latestunless you setenableCrossOsArchive. - Don't put in timestamps, run numbers or commit SHAs in the key as they will cause a miss on every run and will eat up the 10GB quota.
- Keys max out at 512 characters. Any keys longer than that fail the step.
- Put a version prefix in the key (
v1-${{ runner.os }}-npm-...) and bump it tov2-to force a clean cache without actually deleting anything.
How Do You Skip the Install Step on a Cache Hit?
Use the cache hit output and only with an exact key. As restore-keys matches report false, a partial restore will still go ahead and run the install. The key will include the Node version as node_modules with native addons breaks across Node majors.
- uses: actions/cache@v6
id: deps
with:
path: node_modules
key: ${{ runner.os }}-node24-modules-${{ hashFiles('package-lock.json') }}
- if: steps.deps.outputs.cache-hit != 'true'
run: npm ciHow Do You Save the Cache in the Event of Test Failures?
Split restore and save. actions/cache will only save the cache when the job succeeds, so a red test run will never write the cache. This pattern will save the cache when the tests fail, but the install has succeeded.
The actions/cache README has documentation for actions/cache/restore and actions/cache/save in this scenario.
- uses: actions/cache/restore@v6
id: restore
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
- run: npm ci
id: install
- run: npx playwright test
- uses: actions/cache/save@v6
if: always() && steps.install.outcome == 'success' && steps.restore.outputs.cache-hit != 'true'
with:
path: ~/.npm
key: ${{ steps.restore.outputs.cache-primary-key }}The cache-hit != 'true' guard is important as an existing key can't be overwritten and the install check keeps a half-installed package out of an immutable cache entry.
Why Is My GitHub Actions Cache Not Restoring?
A GitHub Actions cache will usually fail to restore as the key (path, OS, branch scope) is different from that of the run that saved it. Check the log of the restore step first as it will print out the key it was looking for and the key it actually matched.
| Symptom | Likely cause | Fix |
|---|---|---|
| Miss on every run | Key includes a value that changes each run | Key on runner.os + lockfile hash only |
Restored, but cache-hit is false | Matched a restore-keys prefix | Expected; keep the install step running |
| Feature branch never sees a cache | Cache was saved on a sibling branch | Save once on the default branch (for example on push to main) |
| Cache saved in a PR is missing later | PR caches are scoped to refs/pull/<n>/merge | Only re-runs of that PR can restore it |
| Works on Linux, misses on Windows | Cache version differs by OS | Add enableCrossOsArchive: true or key per OS |
| Same key, still a miss | path changed, which changes the cache version | Use the same path value in save and restore |
| Never saved at all | The job failed, or the trigger is read-only | Use actions/cache/save with if: always(); check the trigger |
| Cache restores stale content | The key did not change when it should have | Bump the key's version prefix (v1- to v2-) |
Since June 2026, triggers that non-collaborators can start (e.g. pull_request_target and issue_comment) will get read-only cache tokens when they run against the default branch. A save attempt will log a warning and the job will continue (GitHub changelog, June 26, 2026).
What Are the GitHub Actions Cache Limits?
The default GitHub Actions cache limit is 10GB per repository. Anything not accessed in 7 days gets deleted, and when a repo goes over the limit, GitHub will delete the caches by last date of access (oldest first). Those figures are from the GitHub docs as of Nov 2026.
- Size: 10 GB per repository by default. Enterprise owners, organization owners or repository administrators can raise it. User-owned repositories can go up to 10 TB per repository, while organization and enterprise settings set the limit for the rest. Usage above 10 GB is billed.
- Count: no limit on the number of cache entries.
- Rate limits: 200 uploads and 1,500 downloads per minute per repository.
- Budget: if a configured budget is exceeded, the cache becomes read-only.
- Access control: the
cache-modesetting takesread,write,write-onlyornoneat workflow or job level, and a job setting overrides the workflow (GitHub changelog, Sep 10, 2026).
Many of the short-lived branch caches are the reason a repo hits 10GB. Once it does, eviction can easily remove the default branch cache that all the other branches depend on.
How Do You Delete or Clear a GitHub Actions Cache?
You can delete a GitHub Actions cache from the repository's Caches page, with the gh cache delete command, or with a workflow that cleans up when a pull request closes. Deleting needs write access to the repository.
From the web UI: go to the repository's Actions tab, select Caches under Management in the sidebar, filter by branch or key:, and then click the trash icon next to the entry you want to delete (GitHub docs).
From the terminal with GitHub CLI (flags from the gh cache delete manual):
gh cache list --limit 20 # see keys, sizes and last use
gh cache delete Linux-npm-abc123 # delete one cache by key
gh cache delete --all --ref refs/heads/old-branch
gh cache delete --all # clear every cache in the repoAutomatically when a PR closes:
name: Clean up PR caches
on:
pull_request:
types: [closed]
jobs:
cleanup:
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Delete this PR's caches
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
PR_REF: refs/pull/${{ github.event.pull_request.number }}/merge
run: gh cache delete --all --ref "$PR_REF" --succeed-on-no-caches--succeed-on-no-caches will keep the job green if the PR has saved nothing at all; any other error and it will fail. On PRs from forks, the GITHUB_TOKEN is read-only, so this job will fail in that case. GitHub's manage-caches page will point fork setups to pull_request_target and make clear the security implications of that.
Should You Cache Playwright Browsers?
The Playwright CI guide doesn't recommend caching the browser binaries as restoring them takes pretty much as long as downloading them. On Linux you can't cache the OS dependencies anyway. Instead cache the npm store and just keep 'npx playwright install --with-deps' as a normal step.
How Does HyperExecute Handle Dependency Caching?
HyperExecute caches dependencies by default if your hyperexecute.yaml is version 0.2. The YAML 0.2 docs state you don't need to list any directories in order to achieve this.
To take control of the cache yourself, just add cacheKey and cacheDirectories. HyperExecute will hash the files listed in cacheKey, will re-use the cache whilst those files remain unchanged and will create a new cache entry upon a successful job. The following example uses the Maven values from the HyperExecute YAML reference:
version: 0.2
runson: linux
autosplit: true
concurrency: 2
cacheKey: '{{ checksum "pom.xml" }}'
cacheDirectories:
- .m2
pre:
- mvn dependency:resolve
framework:
name: maven/testngGitHub Actions kicks off the run with a single step. Your TestMu AI username and access key should be stored as repository secrets (see the GitHub Actions secrets guide); the step terminates if either of those is missing.
- name: Run tests on HyperExecute
env:
LT_USERNAME: ${{ secrets.LT_USERNAME }}
LT_ACCESS_KEY: ${{ secrets.LT_ACCESS_KEY }}
run: |
: "${LT_USERNAME:?Set the LT_USERNAME repository secret}"
: "${LT_ACCESS_KEY:?Set the LT_ACCESS_KEY repository secret}"
curl -fsSL https://downloads.lambdatest.com/hyperexecute/linux/hyperexecute -o hyperexecute
chmod +x hyperexecute
./hyperexecute --user "$LT_USERNAME" --key "$LT_ACCESS_KEY" --config hyperexecute.yamlThe HyperExecute GitHub Actions page covers AutoSplit, retries and artifacts. Boomi reports 78% faster test execution on that page (as of Nov 2026).
What the docs say you should know first:
- Adding
cacheKeyandcacheDirectoriesturns off the default caching, and HyperExecute will just use what you've specified. - The YAML 0.2 page does not list which package managers the default caching covers.
- Resources cached with
cacheTestURLare not shared between VMs. Each VM has its own copy. - YAML 0.2 drops
testDiscovery,testRunnerCommandand matrix mode. - The documentation doesn't really tell you how a workflow should gate a PR on the HyperExecute result, but the CLI exits with code 1 (
Failed tasks found.) when a test fails, so the GitHub Actions step fails with it.
The 8-Point GitHub Actions Cache Checklist
Run these eight checks before you merge a caching change.
- The key uses
runner.osplus a lockfile hash and nothing that changes on every run. cache-hitgates an install step only if the key is exact and there are norestore-keysin place.- The default branch does the caching so feature branches and PRs can read it.
- The
cache:input onsetup-node,setup-pythonorsetup-javais attempted prior to a hand-writtenactions/cachestep. - Paths are the same in every restore and save.
- There are no secrets, tokens or
.envfiles residing within a cached path. - Playwright browser binaries don't get into the cache unless you actually measure a gain.
- A cleanup job or
gh cache deleteroutine will keep the branch caches under the 10GB limit.
Teams running a GitHub Actions matrix should apply check 1 per matrix leg (i.e. per OS) as each OS will need its own cache.
Watch: How HyperExecute Installs Your Test Dependencies
How to set up your runtime environment with HyperExecute is a 3-minute demo of how HyperExecute will install your test dependencies using the runtime setting.
Conclusion
Start with the cache input on your setup action, key custom caches on the OS and lockfile hash and save from the default branch so that every branch gets a warm start. When the cache stops restoring, check the requested key, path, OS and branch in the restore log. Clear out any stale branch caches with gh cache delete before they push the default branch cache out of the 10GB quota.
Cut your setup time across a parallel suite. HyperExecute will run your Selenium/Playwright/Cypress suite from a single GitHub Actions step and cache dependencies by default (with YAML 0.2).
Was this helpful?
Authors

Japneet Singh Chawla
Author · 15 posts
Japneet Singh Chawla is an Engineering Manager at TestMu AI, where he leads a team driving HyperExecute, the AI-native Test Orchestration Cloud Platform, and integrations with Cypress, Provar, Tosca, and Selenium, improving test execution efficiency and driving adoption across 500+ enterprise clients. He also spearheaded zero-downtime deployments that cut release-related downtime by 90%, and mentors new engineers into productive contributors. He brings 9+ years of experience building and scaling distributed systems, SaaS platforms, and developer tools, with deep hands-on backend engineering across Golang, Python, Node.js, Kafka, and Redis. Earlier at Sumo Logic he built award-winning developer tools, including a VS Code Parser Linter, and at Indus Valley Partners he was a founding member of the Sentiment Analyzer team, building ML-powered solutions for financial clients. Japneet holds an MCA in Computer Science from GGSIPU.
Mayank Bhola
Reviewer
Mayank Bhola is Co-Founder and Head of Products at TestMu AI, where he leads the entire product portfolio across KaneAI, Kane CLI, HyperExecute, SmartUI, the Real Device Cloud, Accessibility, and other software testing product lines. As an early Lead Architect he designed and built the company's flagship Tunnel technology from scratch, created the React-based automation platform, and architected the data-intensive pipelines and FAAS services that scale it. He brings more than 10 years of experience in software development and product engineering, with earlier roles as Head of Technology at Juggernaut Books and Senior Software Engineer at PressPlay TV and Zomato. Mayank holds a B.Tech in Computer Engineering from JIIT Noida.
GitHub Actions Cache FAQs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance
- Advanced access controls
- Advanced data retention rules
- Advanced Local Testing
- Premium Support options
- Early access to beta features
- Private Slack Channel
- Unlimited Manual Accessibility DevTools Tests




