Just jumping in here, I’ve run into the same issue. From what I can tell, docker system prune does remove cache mounts by default, which can be problematic for local dev environments where those caches save a lot of rebuild time.
There doesn’t seem to be an official flag to exclude type=cache mounts specifically. One workaround I’ve seen is to manually clean up other resources (docker image prune, docker container prune, etc.) instead of using the blanket system prune, but that’s more manual.
It would be great if there were a way to mark certain cache mounts as persistent or protected from pruning. If anyone knows of an update or config option for this, I’d be interested too.