Git Advanced: Monorepo, Submodules & Workflows · บทเรียน

การแคชการบิลด์และการบิลด์เฉพาะส่วนที่ได้รับผลกระทบ

รักษาความเร็วของ CI ใน monorepo เมื่อระบบเติบโตขึ้น โดยใช้กราฟงาน แคชผลการคำนวณ และการตรวจจับโครงการที่ได้รับผลกระทบ เพื่อบิลด์และทดสอบเฉพาะสิ่งที่เปลี่ยนแปลง

บทเรียน 4 จาก 413 ขั้นตอน

การแคชการบิลด์และการบิลด์เฉพาะส่วนที่ได้รับผลกระทบ เป็นบทเรียน Git Advanced: Monorepo, Submodules & Workflows ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Git Advanced: Monorepo, Submodules & Workflows และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Git Advanced: Monorepo, Submodules & Workflows มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

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.

เริ่มต้นได้ฟรี

เรียนรู้ Git Advanced: Monorepo, Submodules & Workflows ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “การแคชการบิลด์และการบิลด์เฉพาะส่วนที่ได้รับผลกระทบ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การแคชการบิลด์และการบิลด์เฉพาะส่วนที่ได้รับผลกระทบ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Git Advanced: Monorepo, Submodules & Workflows ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Git Advanced: Monorepo, Submodules & Workflows มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การแคชการบิลด์และการบิลด์เฉพาะส่วนที่ได้รับผลกระทบ”

รักษาความเร็วของ CI ใน monorepo เมื่อระบบเติบโตขึ้น โดยใช้กราฟงาน แคชผลการคำนวณ และการตรวจจับโครงการที่ได้รับผลกระทบ เพื่อบิลด์และทดสอบเฉพาะสิ่งที่เปลี่ยนแปลง คุณปฏิบัติ Git Advanced: Monorepo, Submodules & Workflows ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Git Advanced: Monorepo, Submodules & Workflows หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Git Advanced: Monorepo, Submodules & Workflows บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “การแคชการบิลด์และการบิลด์เฉพาะส่วนที่ได้รับผลกระทบ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Git Advanced: Monorepo, Submodules & Workflows นี้ได้ไหม

ได้ บทเรียน Git Advanced: Monorepo, Submodules & Workflows ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การจัดการการพึ่งพาใน Monorepo
  2. คอมมิตแบบอะตอมและการเปลี่ยนแปลงข้ามโครงการ
  3. กลยุทธ์ CI/CD สำหรับ Monorepo
  4. การแคชการบิลด์และการบิลด์เฉพาะส่วนที่ได้รับผลกระทบ
← กลับไปที่ Git Advanced: Monorepo, Submodules & Workflows