Build cache effectiveness and locality
Worked example
This is an offline lesson. Data are fictional and Docker commands are unexecuted. Any optional execution requires an authorized disposable VM, a verified context, synthetic data, restricted access and no external transmission. Do not collect secrets or private output. Before any separately authorized Docker query, verify the effective endpoint and builder (including environment overrides), not just the context name. Use only disposable lab resources; a failed check is a stop condition, not permission to retry against a different host.
Synthetic plain-progress summary (selected executable steps only):A: 6 eligible, 4 cached, 2 executed; elapsed=40 sB: 6 eligible, 5 cached, 1 executed; elapsed=15 shit rate A=4/6=66.67%; B=5/6=83.33%Example ordering: COPY dependency manifests -> install -> COPY source -> buildExclude skipped, export and metadata steps from this defined count.First define which steps you count; progress output may contain metadata and internal operations that should not be mixed into an instructional hit rate. Put stable inputs before frequently edited files, and use dependency locks. COPY changes can invalidate dependent work; a RUN instruction may reuse a cached result even when a remote package source has changed. A cache mount can retain downloaded packages across builds but does not make the entire RUN step a cache hit. External cache availability, builder location and export/import cost affect results. Use trusted cache sources only, and keep builds correct even when caches are absent. A --no-cache build bypasses normal layer reuse but does not guarantee an empty cache mount or absence of downloaded base images; use a separately prepared disposable environment to define a truly cold trial. Never clear shared caches for a lesson. For the worksheet, count only the specified executed or cached eligible steps; a skipped stage is not a cache hit. Compare identical output exporters and verify correct outputs with or without cache. A cold trial must state base-image availability, layer cache and cache-mount state separately.
Common mistake
A higher hit rate alone does not establish a faster build. Measure expensive misses and total duration.
Manual practice
Calculate hit rates for 7/10 and 8/10 cached steps. If the second build takes longer because a compiler step missed, propose a test isolating source changes and dependency changes.
Worksheet: lab-fixtures/docker-performance-engineering/03-cache-hit-rate/scenario.txt.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Build cache effectiveness and locality — Knowledge check
Interpret performance evidence and make a safe operational decision.
What is the first example hit rate?
Does --no-cache guarantee an empty package cache mount?
What is a sensible optimization?