diff --git a/gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache/GcpBuildCacheService.kt b/gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache/GcpBuildCacheService.kt index 879f0e5..61d058c 100644 --- a/gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache/GcpBuildCacheService.kt +++ b/gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache/GcpBuildCacheService.kt @@ -64,6 +64,7 @@ internal class GcpBuildCacheService( } override fun store(key: BuildCacheKey, writer: BuildCacheEntryWriter) { + if (writer.size == 0L) return // do not store empty entries into the cache logger.info("Storing ${key.blobKey()}") val cacheKey = key.blobKey() val output = ByteArrayOutputStream() diff --git a/gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache/GcpStorageService.kt b/gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache/GcpStorageService.kt index cb701d3..d4c2b02 100644 --- a/gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache/GcpStorageService.kt +++ b/gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache/GcpStorageService.kt @@ -57,7 +57,6 @@ internal class GcpStorageService( } override fun store(cacheKey: String, contents: ByteArray): Boolean { - if (!isEnabled) { logger.info("Not Enabled") return false @@ -123,7 +122,10 @@ internal class GcpStorageService( if (storage == null) return null return try { val blob = storage.service.get(blobId) ?: return null - return if (blob.size > sizeThreshold) { + return if (blob.size == 0L) { + // return empty entries as a cache miss + null + } else if (blob.size > sizeThreshold) { val path = FileHandleInputStream.create() blob.downloadTo(path) path.handleInputStream()