Skip to content
Calcrivo

Docker Cache Efficiency Calculator

Measure how much build time you save from Docker layer cache hits versus misses.

Inputs

layers

Total build layers in the Dockerfile.

layers

Layers served from cache (cache hits).

seconds

Average time to build one layer from scratch.

seconds

Time to load a cached layer (near-instant, but not zero).

Time Saved by Cache

116.0seconds

Speedup Factor

2.8×

Cache Hit Rate

66.7%

Cached Build Time

64.0seconds

Step by step

  1. Cache hit rate

    8 / 12

    = 66.7%

  2. Full build (no cache)

    12 × 15s

    = 180s

  3. With cache

    4 × 15s + 8 × 0.5s

    = 64.0s

  4. Speedup factor

    180 / 64.0

    = 2.8×

How it works

Docker caches layers by instruction hash. If a layer's inputs haven't changed, it's served instantly from cache. Time saved = (cachedLayers × avgBuildTime) − (cachedLayers × cacheLoadTime). Higher cache hit rates yield dramatic build speedups.

Formula

Time Saved

saved = cachedLayers × (avgBuildTime − cacheLoadTime)

cachedLayers
Number of cache hits
avgBuildTime
Seconds to build a layer from scratch
cacheLoadTime
Seconds to load from cache

Frequently Asked Questions

Why does one changed layer invalidate all subsequent layers?

Docker's layer cache is linear — if layer N changes, layers N+1, N+2, etc. must all rebuild because they could depend on N's output. This is why ordering matters: put stable layers first.

How can I improve cache hits in CI?

Use BuildKit's --cache-from with a registry cache, or mount package manager caches (e.g. --mount=type=cache for npm, pip) so dependencies aren't re-downloaded on every build.

You might also need