Caching delle build e build solo dei progetti interessati
Mantenga veloce la CI del monorepo anche quando cresce: usi grafi delle attività, caching dei calcoli e rilevamento dei progetti interessati per compilare e testare solo ciò che è cambiato.
Caching delle build e build solo dei progetti interessati è una lezione Git Advanced: Monorepo, Submodules & Workflows gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Git Advanced: Monorepo, Submodules & Workflows, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Git Advanced: Monorepo, Submodules & Workflows include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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 graphAffected 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=mainWhy 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 --allCache 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/mainTooling 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.
Impara Git Advanced: Monorepo, Submodules & Workflows con un tutor IA — gratis
Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.
- Corsi
- 12
- Lezioni
- 48
Domande Frequenti
La lezione «Caching delle build e build solo dei progetti interessati» è gratuita?
Sì — il testo completo di «Caching delle build e build solo dei progetti interessati» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Git Advanced: Monorepo, Submodules & Workflows, passa a CoddyKit PRO. Il corso Git Advanced: Monorepo, Submodules & Workflows include 4 lezioni in totale.
Cosa imparerò in «Caching delle build e build solo dei progetti interessati»?
Mantenga veloce la CI del monorepo anche quando cresce: usi grafi delle attività, caching dei calcoli e rilevamento dei progetti interessati per compilare e testare solo ciò che è cambiato. Eserciti Git Advanced: Monorepo, Submodules & Workflows con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Git Advanced: Monorepo, Submodules & Workflows?
Non è richiesta alcuna esperienza precedente. Git Advanced: Monorepo, Submodules & Workflows su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Caching delle build e build solo dei progetti interessati»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Git Advanced: Monorepo, Submodules & Workflows?
Sì. Ogni lezione Git Advanced: Monorepo, Submodules & Workflows include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Gestione delle dipendenze nei monorepo
- Commit atomici e modifiche tra progetti
- Strategie CI/CD per monorepo
- Caching delle build e build solo dei progetti interessati