Skip to content

Commit 9f20af4

Browse files
authored
Merge pull request moby#4114 from jedevc/docs-expand-cachemap
Improve CacheMap developer documentation
2 parents 397f69e + 2631f5d commit 9f20af4

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

docs/dev/solver.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,36 @@ calculate a cache key for a vertex and another how to execute it.
137137
`CacheMap` is a description for calculating the cache key. It contains a digest
138138
that is combined with the cache keys of the inputs to determine the stable
139139
checksum that can be used to cache the operation result. For the vertexes that
140-
don't have inputs(roots), it is important that this digest is a stable secure
140+
don't have inputs (roots), it is important that this digest is a stable secure
141141
checksum. For example, in LLB this digest is a manifest digest for container
142142
images or a commit SHA for git sources.
143143

144144
`CacheMap` may also define optional selectors or content-based cache functions
145-
for its inputs. A selector is combined with the input cache key and useful for
146-
describing when different parts of an input are being used, and inputs cache
147-
key needs to be customized. Content-based cache function allows computing a new
148-
cache key for an input after it has completed. In LLB this is used for
149-
calculating cache key based on the checksum of file contents of the input
150-
snapshots.
145+
for its inputs.
146+
147+
- A selector is combined with the cache key of an input, to create a modified
148+
version of that key. In LLB this is used for describing when different
149+
files of an input snapshot are being used.
150+
- A content-based cache function allows computing a new cache key for an input
151+
after it has completed. In LLB this is used for calculating a cache key based
152+
on the checksum of file contents of the input snapshots.
153+
154+
> **Note**
155+
>
156+
> For example, in the case of LLB, if a vertex is a FileOp that copies a file
157+
> from one snapshot to another, the selector can be set to the path of the
158+
> source file in the input snapshot, while the content-based cache function can
159+
> be used to calculate the checksum of the file contents.
160+
>
161+
> If the source path changes, we need to invalidate the cache (which we do by
162+
> changing the selector). However, if we do a content-based cache lookup for
163+
> the input, then the file content may not have changed (which we can detect by
164+
> hashing the file contents). In this case, we can reuse the cache result even
165+
> when the source path has changed.
166+
>
167+
> This abstraction allows the [scheduler](#scheduler) to determine whether to
168+
> perform a quick selector-based cache lookup or a slower content-based cache
169+
> lookup.
151170
152171
`Exec` executes the operation defined by a vertex by passing in the results of
153172
the inputs.

0 commit comments

Comments
 (0)