Yes, Buildkit allows for this with the `--mount=type=cache` functionality. [0]'
Now as an end user you still have to add this to your Dockerfile, but if subsequent builds are able to continually use this cache, build times will drastically improve.
One of the reasons we created Depot is that cache mounts aren't supported in GitHub Actions, since each CI run is entirely ephemeral, so the files saved in a cache mount aren't saved across runs. BuildKit doesn't export those cache types via cache-to. There are some manual workarounds creating tarballs of the BuildKit context directory, but we wanted something that just works without needing to save/load tarballs, which can be quite slow.
How do you invalidate the cache / do a clean build? I've previously seen errors sneak in to docker builds due to cache - where perhaps an upstream docker image was gone, or other dependencies had changed (most likely to happen if a license is changed, or something is yanked due to a security issue).
Now as an end user you still have to add this to your Dockerfile, but if subsequent builds are able to continually use this cache, build times will drastically improve.
- [0] https://docs.docker.com/build/cache/