Docker Cache Efficiency Calculator
Measure how much build time you save from Docker layer cache hits versus misses.
About Docker Cache Efficiency Calculator
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
Worked example
With the default values below, Docker Cache Efficiency Calculator returns Time Saved by Cache of 116.0. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Total Layersaccepts 1–500 layers
- 12 layers
- Cached Layersaccepts 0–500 layers
- 8 layers
- Avg Layer Build Timeaccepts 0–36,000 seconds
- 15 seconds
- Cache Load Time per Layeraccepts 0–60 seconds
- 0.5 seconds
Results
- Time Saved by Cache
- 116.0 seconds
- Speedup Factor
- 2.8 ×
- Cache Hit Rate
- 66.7%
- Cached Build Time
- 64.0 seconds
Step by step
- 1Cache hit rate= 66.7%
- 2Full build (no cache)= 180s
- 3With cache= 64.0s
- 4Speedup factor= 2.8×
Assumptions and limits
- The result is derived only from the 4 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax or compounding frequency into account.
- Figures are rounded for display to 1 decimal place, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
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.
Related Calculators
- Docker Build Time Estimator
- Docker Multi-stage Build Savings Calculator
- Docker Layer Size Calculator
- Docker Bridge Network Calculator
- Docker Container Density Calculator
- Docker Container Memory Calculator
- Docker Container Startup Time Calculator
- Docker CPU Limit Calculator
- Docker Image Compression Calculator
- Docker Image Size Calculator
