Your workflow has a cache step, but the log keeps saying Cache not found for input keys, or the cache restores and the install step still takes as long as before. Either way the cache isn't doing its job.

This post covers how actions/cache decides what to restore, the causes of a miss and how to spot each one, and a short script that counts your real hit rate from the run logs.

What the log is telling you

The cache step prints one of three lines. These come straight from the actions/cache source (v6.1.0):

Cache restored from key: Linux-npm-3f1c... Cache not found for input keys: Linux-npm-3f1c..., Linux-npm- Cache hit occurred on the primary key Linux-npm-3f1c..., not saving cache. 

The first means something was restored, but not always the entry you wanted. The second means nothing matched at all. The third appears in the post-job save step and only when the restore was an exact match.

The cache-hit output follows the same split, with one trap:

What happened cache-hit
Exact match on key true
Matched a restore-keys prefix false
Nothing matched not set (empty)

So if: steps.cache.outputs.cache-hit != 'true' runs the install on both a partial match and a full miss. That's usually what you want. But a check like == 'false' skips the install on a full miss, because the output is empty, not false.

How a match is chosen

When the step runs, GitHub looks for a cache in this order:

  1. An exact match on key
  2. A prefix match on key
  3. Each line of restore-keys, in order, as a prefix

It tries all three on the current branch first, then repeats them on the default branch. A pull request also checks its base branch.

current branch: key (exact) → key (prefix) → restore-keys, in order then the default branch, in the same order 

Two more rules matter. A run can't restore caches made on sibling or child branches. And caches saved by a pull request are scoped to that PR's merge ref, so only re-runs of the same PR can use them.

On top of the key, every entry carries a version, built from the path list and the compression tool. Same key, different path, and it's a different cache.

The six causes of a miss

1. The key changes every run

Start here. The key includes something that's different on every run or commit, such as github.sha, github.run_id or a date. Or it hashes a broad glob like **/*.json that picks up files edited in most commits.

# Misses on every commit: the SHA is new each time key: ${{ runner.os }}-build-${{ github.sha }} 

Compare the key in two consecutive logs. If it differs and your lockfile didn't change, you've found it. Hash only the lockfile, for example hashFiles('**/package-lock.json'), and keep run-specific values out of the key.

2. The cache was only ever saved on another branch

A feature branch can read caches from itself and the default branch, never from a sibling. If your workflow only runs on pull_request, every PR saves to its own merge ref and the next PR starts cold.

The giveaway is a miss on the first run of every new PR while re-runs of the same PR hit. Also run the workflow on push to the default branch, so a cache exists there for every branch to fall back on.

on: push: branches: [main] pull_request: 

3. The job failed, so nothing was saved

The save step only runs when the job succeeds (post-if: success() in the action). A job that fails after the restore never writes a new entry, so the next run misses again. Flaky tests can keep a cache from ever being created.

In a failed run the post-job cache step doesn't run, and the log has no Cache saved with key. To keep the cache independent of the tests, split the step into actions/cache/restore and actions/cache/save, and run the save step with if: always() right after the install, before the tests.

- uses: actions/cache/restore@v6 id: cache with: path: ~/.npm key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }} - run: npm ci - uses: actions/cache/save@v6 if: always() && steps.cache.outputs.cache-hit != 'true' with: path: ~/.npm key: ${{ steps.cache.outputs.cache-primary-key }} - run: npm test 

4. The path or OS doesn't match

Changing the path list changes the cache version, so an entry saved with the old paths won't restore even with the same key. Caches saved on Windows don't restore on Linux or macOS, or the other way round, unless you set enableCrossOsArchive: true.

Suspect this when the misses started right after a change to path, or when only Windows jobs miss. Keep path identical in every step that touches that key, and put ${{ runner.os }} (and the architecture, if you build on both) at the start of the key.

5. The entry was evicted

GitHub removes entries that haven't been used in 7 days. Each repository gets 10 GB of cache by default, and when it's full the least recently used entries go first. If several large caches are saved on every run, new entries can push out ones you still need.

Open the Caches page under the repo's Actions tab. Usage close to the limit, or a missing entry you expected, points here. The options are to cache less (for example ~/.npm instead of node_modules), drop caches nobody restores, or raise the limit. GitHub now lets repository admins, organization owners and enterprise owners raise it above 10 GB. Some runner providers also run their own cache backend. WarpBuild's is a drop-in replacement for actions/cache with no size cap, though it doesn't work on Windows runners.

6. The key never changes, so the cache goes stale

The opposite problem. An exact hit skips the save step, so if the key stays the same while the contents change, the old entry is restored forever. Restores succeed, but the install step does most of the work anyway.

The log says Cache hit occurred on the primary key, yet the install still downloads most packages. Make the key depend on the lockfile, and put the broad fallback in restore-keys, not in key.

Count your real hit rate

The Actions UI doesn't show a hit rate, but the run logs do. This counts outcomes across the last 30 runs of one workflow on main with the GitHub CLI:

p='Cache restored from key' p+='|Cache not found for input keys' p+='|Cache hit occurred on the primary key' p+='|Cache saved with key' for id in $(gh run list --workflow ci.yml --branch main \ --limit 30 --json databaseId \ --jq '.[].databaseId'); do gh run view "$id" --log done | grep -oE "$p" | sort | uniq -c 

Each line maps to one outcome:

  • Cache hit occurred on the primary key is an exact hit. It comes from the save step, which skips saving because the entry already exists.
  • Cache restored from key counts every restore, exact or partial. Subtract the exact hits to get the partial ones.
  • Cache not found for input keys is a full miss.
  • Cache saved with key means the run wrote a new entry, which only happens after a partial hit or a miss.

You don't need a benchmark to judge the result. On main, with a lockfile that rarely changes, almost every run should be an exact hit, and saves should only appear on the runs where the lockfile changed. When the counts don't look like that, they point at a cause:

What the counts show Where to look
A save on nearly every run The key changes every run (cause 1)
Misses that cluster after failed runs Failed jobs never save (cause 3)
Misses after a gap of a week or more, or on a busy repo Eviction (cause 5)
Exact hits on every run, but the install is still slow The key never changes (cause 6), or the entry is too big (see below)

Two caveats. The save step doesn't run when a job fails, so an exact hit in a failed run shows up only as "restored". And count per workflow, because one workflow with a bad key gets hidden in a repo-wide number.

Quick recipes

These are the keys that avoid causes 1 and 6 for the three most common setups.

  • npm: actions/setup-node with cache: npm handles the key for you, based on package-lock.json. With actions/cache, cache ~/.npm rather than node_modules.
  • pip: actions/setup-python with cache: pip keys on requirements.txt or pyproject.toml. Set cache-dependency-path if your dependencies live in other files, or in several of them.
  • Gradle: gradle/actions/setup-gradle manages its own cache. Don't add an actions/cache step for ~/.gradle, or setup-java with cache: gradle, on top of it.

When the miss isn't the problem

Sometimes the cache hits and the step is still slow. A multi-gigabyte entry can take longer to download and unpack than a fresh install on a fast network. If restore time is close to install time, cache less: the package manager's download cache instead of the installed tree, or one entry per job instead of one huge shared entry. Upload limits matter too: GitHub allows 200 cache uploads per minute per repository, so a large matrix all saving at once can get rate limited.

Checklist

  • The key hashes only the lockfile and starts with runner.os
  • path is identical everywhere the key is used
  • The workflow runs on push to the default branch, so PRs have something to fall back on
  • The save step runs even when tests fail
  • if: conditions compare against 'true', not 'false'
  • Total cache usage is well under the repository limit
  • The hit rate is counted per workflow, from the logs

Sources: GitHub dependency caching reference and the actions/cache README and source, checked November 26, 2026.