Resist the urge to eagerly invalidate cache entries unless you have definitive proof that the cached data is invalid and cannot provide value for future operations. Cache entries can still be valuable even when their associated remote artifacts have expired or been removed.
Resist the urge to eagerly invalidate cache entries unless you have definitive proof that the cached data is invalid and cannot provide value for future operations. Cache entries can still be valuable even when their associated remote artifacts have expired or been removed.
The key principle is that cache invalidation should be conservative - err on the side of keeping potentially useful cache entries rather than aggressively removing them. Even when remote cache artifacts are no longer available, the local cache entry may still save build time for actions whose outputs are never materialized.
Consider these approaches instead of eager invalidation:
Example of conservative cache management:
if (actionCache != null && token != null) {
// Don't eagerly delete - cache entry can still save build time
// for actions whose outputs are never materialized
if (token.dirty) {
actionCache.put(token.key, token.entry);
}
}
// Only clean up definitively stale entries
actionCache.removeIf(entry ->
entry.getOutputFiles().values().stream()
.anyMatch(e -> e.getExpireAtEpochMilli() == SERVER_EXPIRATION_SENTINEL));
This approach maximizes cache hit rates while maintaining correctness, leading to better build performance overall.
Enter the URL of a public GitHub repository