Dependency caching

Cache downloads without skipping installation

Lesson 18 of 20 · 12 min · Module 6: Verify and recover

Caching should improve speed while preserving the installation contract.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Cache the right material
  • Connect cache identity to dependency inputs

The idea

A workflow combines an event boundary, job dependencies, and ordered steps. Conditions and prerequisite outcomes determine which jobs can run.

01Cache the right material

setup-node npm caching preserves package-manager download data. It should not be confused with blindly reusing an arbitrary node_modules directory.

02Connect cache identity to dependency inputs

The lockfile changes when the resolved dependencies change. A cache key that ignores those inputs can reuse the wrong material.

03Keep the clean installation step

npm ci remains part of the workflow even with a cache. The cache changes performance, not the declared dependency validation sequence.

Your turn

Create test with setup-node@v4, node-version "22", cache npm, and cache-dependency-path package-lock.json; then npm ci and npm test.

What the checks look for

  • Configures the dependency cache
  • Still installs before testing
Try it in the editor →

Take this with you

Treat caches as disposable optimizations around a reproducible process.

Go a little further

Describe what a safe cache miss should do to the workflow.

Learn CI/CD & Release Engineering for free

20 short lessons with real code and instant checks.

See the whole course →