Manuals / CI/CD Pipelines / Ch 7

C · Speed & ScaleIntermediate50 min read

7. Caching & pipeline speed

CI/CD Pipelines · 48 pages source format

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

What you'll learn

  • actions/cache
  • Cache keys
  • Dependency review
  • Parallel jobs

Dependency cache

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

- 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.

Clear?

Cache invalidation

Key includes lockfile hash — dependency change busts cache automatically.

Do this now

Bump dependency. Confirm cache miss then new cache save.

Clear?

Parallel jobs

lint, test, build as separate jobs — fail fast on lint before expensive test.

Do this now

Split into lint + test jobs. lint runs first or in parallel.

Clear?

Speed budget

Document target times. Alert when PR check exceeds 10 min.

Do this now

Add timing note to CI.md from last 5 runs.

Clear?

Checklist