File tree Expand file tree Collapse file tree 3 files changed +13
-9
lines changed
src/main/kotlin/com/gabrielfeo/gradle/enterprise/api Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Original file line number Diff line number Diff line change 1+ @file:Suppress(" unused" )
2+
13package com.gabrielfeo.gradle.enterprise.api
24
35import com.gabrielfeo.gradle.enterprise.api.internal.*
@@ -40,17 +42,19 @@ fun shutdown() {
4042}
4143
4244/* *
43- * List of patterns matching API URLs that are OK to store in the HTTP cache. Matches by default:
45+ * Regex pattern to match API URLs that are OK to store in the HTTP cache. Matches by default:
4446 * - {host}/api/builds/{id}/gradle-attributes
4547 * - {host}/api/builds/{id}/maven-attributes
4648 *
47- * By default, the Gradle Enterprise disallows HTTP caching via response headers. This library
49+ * By default, the Gradle Enterprise API disallows HTTP caching via response headers. This library
4850 * removes such headers to forcefully allow caching, if the path is matched by any of these
4951 * patterns.
52+ *
53+ * Use `|` to define multiple patterns in one, e.g. `.*gradle-attributes|.*test-distribution`.
5054 */
51- val cacheablePaths : MutableList < Regex > = mutableListOf (
52- """ .*/api/builds/[\d\w]+/(?:gradle|maven)-attributes """ .toRegex(),
53- )
55+ val cacheableUrlPattern : Regex = System .getenv( " GRADLE_ENTERPRISE_API_CACHEABLE_URL_PATTERN " )
56+ ? .toRegex()
57+ ? : """ .*/api/builds/[\d\w]+/(?:gradle|maven)-attributes """ .toRegex( )
5458
5559/* *
5660 * Maximum amount of concurrent requests allowed. Further requests will be queued. By default,
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ package com.gabrielfeo.gradle.enterprise.api.internal
22
33import com.gabrielfeo.gradle.enterprise.api.accessToken
44import com.gabrielfeo.gradle.enterprise.api.auth.HttpBearerAuth
5- import com.gabrielfeo.gradle.enterprise.api.cacheablePaths
5+ import com.gabrielfeo.gradle.enterprise.api.cacheableUrlPattern
66import com.gabrielfeo.gradle.enterprise.api.internal.caching.CacheEnforcingInterceptor
77import com.gabrielfeo.gradle.enterprise.api.internal.caching.CacheHitLoggingInterceptor
88import com.gabrielfeo.gradle.enterprise.api.internal.caching.cache
@@ -14,7 +14,7 @@ val okHttpClient: OkHttpClient by lazy {
1414 .cache(cache)
1515 .addInterceptor(HttpBearerAuth (" bearer" , accessToken()))
1616 .addInterceptor(CacheHitLoggingInterceptor ())
17- .addNetworkInterceptor(CacheEnforcingInterceptor (cacheablePaths ))
17+ .addNetworkInterceptor(CacheEnforcingInterceptor (cacheableUrlPattern ))
1818 .build()
1919 .apply {
2020 dispatcher.maxRequests = maxConcurrentRequests
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import okhttp3.Response
66import kotlin.time.Duration.Companion.days
77
88internal class CacheEnforcingInterceptor (
9- private val cacheablePaths : List < Regex > ,
9+ private val cacheableUrlPattern : Regex ,
1010) : Interceptor {
1111
1212 private val maxAge = 365 .days.inWholeMilliseconds
@@ -25,5 +25,5 @@ internal class CacheEnforcingInterceptor(
2525 }
2626
2727 private fun isCacheable (request : Request ) =
28- cacheablePaths.any { it. matches(request.url.toString()) }
28+ cacheableUrlPattern. matches(request.url.toString())
2929}
You can’t perform that action at this time.
0 commit comments