Couldn’t find any docs on this, but is it possible...
# caching
r
Couldn’t find any docs on this, but is it possible to ensure that, on local cache hits, the cache entry is pushed to the remote build cache?
f
Hey @Remco Mokveld See https://docs.gradle.org/current/userguide/build_cache.html#sec:build_cache_configure
Copy code
Gradle stores ("pushes") build outputs in any build cache that is enabled and has BuildCache.isPush() set to true.

By default, the local build cache has push enabled, and the remote build cache has push disabled.
So if you configure the remote to be enabled and with push = true It will get the entry, even on a local cache hit.
Be aware that the default is push = false for the remote, just because the recommendation is to enable that on CI only, to avoid a malicious local actor to have write access to the remote cache, and push poisoned entries to it (which would then poison everyone with read access to the remote cache)
But of course, it’s up to you to make that decision.
r
We’re seeing cases where push is set to true, tasks have local cache hits and when I try to locate the cache entry in the console with that cache key it says the cache entry is not available
Probably got evicted at some point
f
possible A support bundle might contain the info on the remote build cache log If you open a task with a local hit, on the timeline of the build scan, do you see a remote store operation ?
r
No
f
and the build cache tab in the performance section shows that the remote is enabled with push = true (and proper authentication is in place if needed) ?
r
Yeah, another task in the same build
f
@wolfs do you mind chiming in ? Am I wrong in believing that a local hit also results in a remote push if configured properly ?
@Remco Mokveld could it be that the remote build cache was disabled during the build due to error (so the store op was not attempted) ? The build cache tab will tell you.
w
A local cache hit never results in a push. What Gradle does on a hit from the remote cache is that it stores the remote build cache entry in the local cache. You could consider this a “push”, though it won’t show up as one in the GE page. For local cache entries, we don’t need to store them locally for obvious reasons. Why do you want to push local cache hits to the remote cache?
f
My bad then, apologies
r
Our CI instances at this point maintain a local build cache and push to remote
w
I still don’t understand the problem: When you have a local and remote miss, then the cache entry will be stored in the local and the remote cache. So it should be fine to not push elements to the remote cache when there is a local cache hit - since it either has been pushed already or it came from the remote cache in the first place.
r
We’re now getting remote cache misses on developer machines because CI has the the entries in their local cache and so if the entry gets evicted from remote it won’t be pushed again
w
Ah, I see. At some point we switched off the local cache on CI for our builds, so you’d also push to the remote cache. I think we turned that off again, since we didn’t have problems with the eviction. You can either do that or change the eviction settings for your remote build cache to keep then entries longer.