0Pricing
Git Advanced: Monorepo, Submodules & Workflows · Lesson

Build Caching and Affected-Only Builds

Keep monorepo CI fast as it grows: use task graphs, computation caching, and affected-project detection to build and test only what changed.

Build Caching and Affected-Only Builds is a free Git Advanced: Monorepo, Submodules & Workflows lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Git Advanced: Monorepo, Submodules & Workflows learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Scaling Wall

As a monorepo grows, rebuilding and retesting everything on every commit becomes painfully slow.

The fix is to only do work that the change actually requires, and to cache results that have not changed.

The Project Dependency Graph

Monorepo tools build a graph of how projects depend on each other. This graph tells the tool what is downstream of any change.

nx graph

Affected Detection

By comparing your branch against a base commit, the tool computes the set of affected projects — those changed plus everything depending on them.

nx affected --target=test --base=main

Why Only Affected

If you change a leaf library, only it and its consumers need rebuilding — unrelated apps are untouched. This can cut CI time from hours to minutes on large repos.

Computation Caching

Tools hash a task's inputs (source files, config, dependencies). If the hash matches a previous run, the cached output is replayed instead of recomputing.

What Goes Into the Hash

The cache key combines:

  • Source file contents
  • The exact command and its options
  • Dependency versions
  • Relevant environment variables

Any change to these invalidates the cache entry.

Local vs Remote Cache

A local cache speeds up your own repeated runs. A remote cache shares results across the whole team and CI, so work done once benefits everyone.

nx run-many --target=build --all

Cache Hits and Misses

A hit replays stored output instantly; a miss runs the task and stores the result. Tools report this so you can see the time saved.

Correctness of Caching

Caching is only safe if tasks are deterministic and inputs are declared accurately. Hidden inputs (timestamps, network calls) cause stale or wrong cache hits.

Wiring It into CI

In CI, run affected targets against the merge base and enable the remote cache. Each pipeline then does the minimum work and reuses shared results.

nx affected --target=build,test,lint --base=origin/main

Tooling Landscape

Popular tools provide these features: Nx and Turborepo for JS/TS, Bazel for polyglot at scale, and Gradle/Pants for JVM. The concepts are the same across all.

Quick Check

Test your build-optimization knowledge.

Recap

You can now keep monorepo CI fast at scale:

  • Use the project dependency graph to compute affected work
  • Cache task results keyed on hashed inputs
  • Share results via a remote cache across team and CI
  • Keep tasks deterministic so caching stays correct

This extends your dependency management and CI/CD strategy lessons.

Frequently asked questions

Is the “Build Caching and Affected-Only Builds” lesson free?

Yes — the full text of “Build Caching and Affected-Only Builds” is free to read here on the web, and the Git Advanced: Monorepo, Submodules & Workflows course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Git Advanced: Monorepo, Submodules & Workflows course, upgrade to CoddyKit PRO.

What will I learn in “Build Caching and Affected-Only Builds”?

Keep monorepo CI fast as it grows: use task graphs, computation caching, and affected-project detection to build and test only what changed. You practise Git Advanced: Monorepo, Submodules & Workflows with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Git Advanced: Monorepo, Submodules & Workflows?

No prior experience is required. Git Advanced: Monorepo, Submodules & Workflows on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Build Caching and Affected-Only Builds” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Git Advanced: Monorepo, Submodules & Workflows lesson?

Yes. Every Git Advanced: Monorepo, Submodules & Workflows lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Dependency Management in Monorepos
  2. Atomic Commits and Cross-Project Changes
  3. Monorepo CI/CD Strategies
  4. Build Caching and Affected-Only Builds
← Back to Git Advanced: Monorepo, Submodules & Workflows