title: How are Docker buildx layer cache hashes calculated?
body: <p>I'm digging into the caching of Docker buildx to try to debug <a href="https://stackoverflow.com/questions/70513463/docker-cache-odd-behaviour-for-pip-install">an issue</a>. I'm trying to figure out how, exactly, buildx checks if a layer is available in the local cache. Although I've searched fairly extensively, I can't seem to find any documentation on this.</p>
  <p>Looking at the local cache files themselves, I see a bunch of files with hash names. My assumption is that it works as follows (assuming use of <code>type=local,mode=max</code>):</p>
  <ol>
  <li>For each line in the Dockerfile, it uses some combination of parameters to calculate a SHA hash.</li>
  <li>It checks in the <code>--cache-from</code> directory to see if a file with that hash as the name exists</li>
  <li>If it does exist, it uses that file as the layer and doesn't re-build anything (and copies that file to the <code>--cache-to</code> directory.</li>
  <li>If it does <em>not</em> exist, it builds the layer and saves it as a file, with that hash as the name, in the <code>--cache-to</code> directory.</li>
  <li>This results in an output cache with 1 file for each line in the Dockerfile.</li>
  </ol>
  <p>So my questions are:</p>
  <ol>
  <li>Is my understanding of this process correct? Am I missing any key elements?</li>
  <li>For step (1) above, what are the &quot;parameters&quot; that it uses to calculate the hash? I would think it's the string value of the line itself, plus the value of any files that are copied by the line (e.g. <code>ADD</code>), but does it use anything else? e.g. the last-modified timestamp of any files that it copies?</li>
  </ol>