@@ -30,7 +30,8 @@ class AwsS3BuildCacheService internal constructor(
3030 private val s3 : AmazonS3 ,
3131 private val bucketName : String ,
3232 private val path : String? ,
33- private val reducedRedundancy : Boolean
33+ private val reducedRedundancy : Boolean ,
34+ private val maximumCachedObjectLength : Long
3435) : BuildCacheService {
3536 companion object {
3637 private const val BUILD_CACHE_CONTENT_TYPE = " application/vnd.gradle.build-cache-artifact"
@@ -49,6 +50,16 @@ class AwsS3BuildCacheService internal constructor(
4950 val bucketPath = key.getBucketPath()
5051 try {
5152 s3.getObject(bucketName, bucketPath).use { s3Object ->
53+ if (s3Object.objectMetadata.contentLength > maximumCachedObjectLength) {
54+ logger.info(
55+ " Cache item '{}' '{}' in S3 bucket size is {}, and it exceeds maximumCachedObjectLength {}. Will skip the retrieval" ,
56+ key.displayName,
57+ bucketPath,
58+ s3Object.objectMetadata.contentLength,
59+ maximumCachedObjectLength
60+ )
61+ return false
62+ }
5263 reader.readFrom(s3Object.objectContent)
5364 }
5465 return true
@@ -76,6 +87,17 @@ class AwsS3BuildCacheService internal constructor(
7687
7788 override fun store (key : BuildCacheKey , writer : BuildCacheEntryWriter ) {
7889 val bucketPath = key.getBucketPath()
90+ val itemSize = writer.size
91+ if (itemSize > maximumCachedObjectLength) {
92+ logger.info(
93+ " Cache item '{}' '{}' in S3 bucket size is {}, and it exceeds maximumCachedObjectLength {}. Will skip caching it." ,
94+ key.displayName,
95+ bucketPath,
96+ itemSize,
97+ maximumCachedObjectLength
98+ )
99+ return
100+ }
79101 logger.info(" Start storing cache entry '{}' in S3 bucket" , bucketPath)
80102 val meta = ObjectMetadata ().apply {
81103 contentType = BUILD_CACHE_CONTENT_TYPE
0 commit comments