Manuals / CI/CD Pipelines / Chapter 7

C · Speed & Scale · intermediate · Week 4–5 · Chapter 7 of 12

Caching & pipeline speed

Slow pipelines get skipped. Cache npm/pip/maven dependencies. Measure before and after.

Path progress
52%

Step 1 of 4

Dependency cache

actions/cache with path and key from lockfile hash. Restore on cache hit.

Dependency cacheDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Dependency cachedrag · tap →Try thisdrag · tap →Follow the dashed drag · tap →

Example

- uses: actions/cache@v4
  with:
    path: ~/.npm
    key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}

Do this now

Add cache step. Compare workflow duration before/after in README.

Was this step clear?
Chapter learning outcomes
  • actions/cache
  • Cache keys
  • Dependency review
  • Parallel jobs

Clear these before you leave

Side quest

Before/after

Screenshot Actions timing with and without cache.