Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Caching · GitHub Actions

Direct answer

Caching in GitHub Actions stores dependencies like npm, pip or Maven files between runs with actions/cache or setup-* cache options, keyed by lock-file hashes to speed up builds.

When to use this

Use this when speeding up GitHub Actions with caching.

First 30 seconds

1. Caching speeds dependencies.

2. Key on lock files.

3. Caches are scoped by branch; PRs can read base caches.

4. Don't cache secrets.

5. setup-* actions have built-in caching.

Operational verification

key → restore → build → save

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
GitHub Actions dependency caching
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformGitHub Actions dependency caching · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when speeding up GitHub Actions with caching.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Verification path Verify boundary

The primary procedure is: Run the job once with a guaranteed cache miss and once with the intended key; inspect cache-hit metadata and verify the build/test result is identical apart from performance. Exercise failure-oriented cases such as stale key design, cache poisoning from low-trust triggers, secrets cached accidentally, partial restore masking dependency drift and cache-hit assumptions breaking clean builds so the test covers failure cases, not only the happy path.

Step 2 Common mistakes Narrow the fault
  • Caching secrets or build outputs that differ per environment.
Step 3 Where it fails Narrow the fault

Failure analysis for GitHub Actions → Caching should follow the path through the components: workflow context → key calculation → cache lookup/permission → archive restore → package/tool validation → optional save. Tests should include edge cases such as stale key design, cache poisoning from low-trust triggers, secrets cached accidentally, partial restore masking dependency drift and cache-hit assumptions breaking clean builds. Recovery should disable or version-bump the suspect key, reproduce on a clean cache miss, repair key/trust scoping, then compare dependency lock data and build/test output.

Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • Key caches on hashes of lock files.
  • setup-node, setup-python and others have built-in caching.
  • A stale or poisoned cache can break builds.
Key checks
  • actions/cache key with hashFiles(lock files) — correct key
  • gh cache list — caches
  • Cache scope per branch — poisoning risk
ReferenceWhy it matters1 section · depth on demand

In depth

Caching in GitHub Actions uses actions/cache (or built-in caching in setup actions) to save directories between runs, keyed by a hash of dependency files.

- uses: actions/setup-python@v5
  with: { python-version: '3.12', cache: pip }
- uses: actions/cache@v4
  with:
    path: ~/.ansible/collections
    key: collections-${{ hashFiles('collections/requirements.yml') }}
LimitDetail
ScopeCaches from the default branch are readable by other branches
SizeRepository cache quota; old entries evicted
Restore keysPartial matches when the exact key misses

Caches are not artifacts: use actions/upload-artifact for files other jobs or people need.

ReferenceImportant terms & boundaries1 section · depth on demand

Mechanics

Caching in GitHub Actions is owned at runtime by the GitHub Actions cache service together with the workflow job and cache action/setup action that computes lookup keys. The durable intent is workflow YAML defining cache paths, exact key, restore keys and the trust context allowed to read or write caches. Reliable automation must carry stable identity across the path: repository, branch/ref scope, workflow run/job, cache key/version and cache entry ID. The consumer-visible target is dependency or intermediate files restored into the runner workspace, never secrets or authoritative build artifacts. The key invariants are keys encode dependency inputs, restored caches are treated as untrusted acceleration data, cache miss remains a valid path and cache contents are reproducible.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
ReferenceConfiguration & state1 section · depth on demand

Lifecycle

Store and review workflow YAML defining cache paths, exact key, restore keys and the trust context allowed to read or write caches; pin or at least record implementation/model versions and keep environment-specific identity outside reusable logic where possible. The stable identity contract is repository, branch/ref scope, workflow run/job, cache key/version and cache entry ID.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docGitHub Actions dependency caching current

Authoritative/upstream documentation reviewed for bounded claims in GitHub Actions > Caching. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://docs.github.com/en/actions/concepts/workflows-and-actions/dependency-caching · confidence 94%
Embedded reference data

Quick lookup tables

GitHub Actions → Caching · operational reference

Context-specific ownership, verification, output and failure-boundary lookup for GitHub Actions → Caching.

LayerGitHub Actions → Caching operational reference
Runtime/ownershipGitHub Actions dependency caching · the GitHub Actions cache service together with the workflow job and cache action/setup action that computes lookup keys
Persistent intentworkflow YAML defining cache paths, exact key, restore keys and the trust context allowed to read or write caches
VerificationRun the job once with a guaranteed cache miss and once with the intended key; inspect cache-hit metadata and verify the build/test result is identical apart from performance.
Expected interpretationThe correct cache scope/key is selected, untrusted contexts cannot gain inappropriate write capability, misses rebuild successfully, and restored data does not alter the verified build result.
Recovery boundarydisable or version-bump the suspect key, reproduce on a clean cache miss, repair key/trust scoping, then compare dependency lock data and build/test output
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

At minimum retain run/job ID, ref, key, restore key matched, cache-hit boolean, cache entry/version, restored paths, save result, build checksum/test result and timing. The useful output makes ambiguity visible, links to the target identity from repository, branch/ref scope, workflow run/job, cache key/version and cache entry ID, and provides enough context to safely decide whether a retry is permitted.

Confirmation

Confirm action

Continue?