@@ -4,6 +4,7 @@ package com.gabrielfeo.gradle.enterprise.api
44
55import com.gabrielfeo.gradle.enterprise.api.internal.*
66import java.io.File
7+ import kotlin.time.Duration.Companion.days
78
89/* *
910 * The global instance of [GradleEnterpriseApi].
@@ -42,19 +43,51 @@ fun shutdown() {
4243}
4344
4445/* *
45- * Regex pattern to match API URLs that are OK to store in the HTTP cache. Matches by default:
46+ * Regex pattern to match API URLs that are OK to store long-term in the HTTP cache, up to
47+ * [longTermCacheMaxAge] (1y by default, max value). By default, uses environment variable
48+ * `GRADLE_ENTERPRISE_API_LONG_TERM_CACHE_URL_PATTERN` or a pattern matching:
4649 * - {host}/api/builds/{id}/gradle-attributes
4750 * - {host}/api/builds/{id}/maven-attributes
4851 *
49- * By default, the Gradle Enterprise API disallows HTTP caching via response headers. This library
50- * removes such headers to forcefully allow caching, if the path is matched by any of these
51- * patterns.
52+ * Gradle Enterprise API disallows HTTP caching, but this library forcefully removes such
53+ * restriction.
5254 *
5355 * Use `|` to define multiple patterns in one, e.g. `.*gradle-attributes|.*test-distribution`.
56+ */
57+ var longTermCacheUrlPattern: Regex =
58+ System .getenv(" GRADLE_ENTERPRISE_API_LONG_TERM_CACHE_URL_PATTERN" )?.toRegex()
59+ ? : """ .*/api/builds/[\d\w]+/(?:gradle|maven)-attributes""" .toRegex()
60+
61+ /* *
62+ * Max age in seconds for URLs to be cached long-term (matched by [longTermCacheUrlPattern]).
63+ * By default, uses environment variable `GRADLE_ENTERPRISE_API_LONG_TERM_CACHE_MAX_AGE` or 1 year.
64+ */
65+ var longTermCacheMaxAge: Long =
66+ System .getenv(" GRADLE_ENTERPRISE_API_SHORT_TERM_CACHE_MAX_AGE" )?.toLong()
67+ ? : 365 .days.inWholeSeconds
68+
69+ /* *
70+ * Regex pattern to match API URLs that are OK to store short-term in the HTTP cache, up to
71+ * [shortTermCacheMaxAge] (1d by default). By default, uses environment variable
72+ * `GRADLE_ENTERPRISE_API_SHORT_TERM_CACHE_URL_PATTERN` or a pattern matching:
73+ * - {host}/api/builds
74+ *
75+ * Gradle Enterprise API disallows HTTP caching, but this library forcefully removes such
76+ * restriction.
77+ *
78+ * Use `|` to define multiple patterns in one, e.g. `.*gradle-attributes|.*test-distribution`.
79+ */
80+ var shortTermCacheUrlPattern: Regex =
81+ System .getenv(" GRADLE_ENTERPRISE_API_SHORT_TERM_CACHE_URL_PATTERN" )?.toRegex()
82+ ? : """ .*/builds(?:\?.*|\Z)""" .toRegex()
83+
84+ /* *
85+ * Max age in seconds for URLs to be cached short-term (matched by [shortTermCacheUrlPattern]).
86+ * By default, uses environment variable `GRADLE_ENTERPRISE_API_SHORT_TERM_CACHE_MAX_AGE` or 1 day.
5487 */
55- val cacheableUrlPattern : Regex = System .getenv( " GRADLE_ENTERPRISE_API_CACHEABLE_URL_PATTERN " )
56- ?.toRegex ()
57- ? : """ .*/api/builds/[\d\w]+/(?:gradle|maven)-attributes """ .toRegex()
88+ var shortTermCacheMaxAge : Long =
89+ System .getenv( " GRADLE_ENTERPRISE_API_SHORT_TERM_CACHE_MAX_AGE " )?.toLong ()
90+ ? : 1 .days.inWholeSeconds
5891
5992/* *
6093 * Maximum amount of concurrent requests allowed. Further requests will be queued. By default,
0 commit comments