Skip to main content
Cloud / DevOpsDeployment StrategiesDiagramIntermediate

Build Cache

KO: 빌드 캐시·EN: Build Cache·JA: ビルドキャッシュ

An optimization technique that reuses previously downloaded dependencies, compiled outputs, and container layers across builds to slash CI/CD duration and compute cost

Table of Contents

Structure Diagram

Cold Build vs Build Cache HIT Duration
Cold Build (8m 30s)3 steps
Cached Build (1m 15s)3 steps
STEP 1Install Deps(3m 10s)
Quick Answer

What is Build Cache?

An optimization technique that reuses previously downloaded dependencies, compiled outputs, and container layers across builds to slash CI/CD duration and compute cost. It is a core concept in Deployment Strategies within Cloud / DevOps.

Core Principles

Build Cache stores intermediate build outputs—downloaded packages, compiled objects, and container layers—indexed by a cryptographic hash of their inputs (lockfiles, source files, and build flags). When inputs remain unchanged, the build system skips redundant work and restores the cached output instantly.

In cloud CI where runners are ephemeral and start clean on every job, a Remote Build Cache is essential to prevent re-downloading dependencies and recompiling untouched code on every commit.

Practical Takeaways

  • Key caches on lockfile hashes: Derive cache keys from package-lock.json, go.sum, or Cargo.lock hashes, with prefix restore-keys for partial fallback hits.
  • Use Docker BuildKit remote & mount caches: Combine --mount=type=cache for package managers with --cache-from=type=registry (or type=gha) so stateless CI runners share layer caches.
  • Eliminate cache busters: Exclude volatile files via .dockerignore and avoid embedding timestamps early in build steps so hashes stay deterministic.

Notable Examples

  • Docker BuildKit / Buildx: Cuts container image build times by 70–90% via remote registry and inline caching.
  • Turborepo, Nx & Bazel: Share remote task caches across CI and developer laptops so monorepos only rebuild affected packages.
  • GitHub Actions Cache & sccache: Persists dependency and compiler caches across ephemeral cloud runners.