Skip to content

Commit e3c3bb0

Browse files
committed
Rename spring.cache.control to spring.cache.cachecontrol
Closes #11090
1 parent 55f7b3a commit e3c3bb0

File tree

5 files changed

+36
-38
lines changed

5 files changed

+36
-38
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import org.springframework.boot.context.properties.ConfigurationProperties;
2525
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
26-
import org.springframework.http.CacheControl;
2726

2827
/**
2928
* Properties used to configure resource handling.
@@ -275,7 +274,7 @@ public static class Cache {
275274
/**
276275
* Cache period for the resources served by the resource handler. If a duration
277276
* suffix is not specified, seconds will be used. Can be overridden by the
278-
* 'spring.resources.cache.control' properties.
277+
* 'spring.resources.cache.cachecontrol' properties.
279278
*/
280279
@DefaultDurationUnit(ChronoUnit.SECONDS)
281280
private Duration period;
@@ -284,7 +283,7 @@ public static class Cache {
284283
* Cache control HTTP headers, only allows valid directive combinations. Overrides
285284
* the 'spring.resources.cache.period' property.
286285
*/
287-
private final Control control = new Control();
286+
private final CacheControl cacheControl = new CacheControl();
288287

289288
public Duration getPeriod() {
290289
return this.period;
@@ -294,14 +293,14 @@ public void setPeriod(Duration period) {
294293
this.period = period;
295294
}
296295

297-
public Control getControl() {
298-
return this.control;
296+
public CacheControl getCacheControl() {
297+
return this.cacheControl;
299298
}
300299

301300
/**
302301
* Cache Control HTTP header configuration.
303302
*/
304-
public static class Control {
303+
public static class CacheControl {
305304

306305
/**
307306
* Maximum time the response should be cached, in seconds if no duration
@@ -459,15 +458,15 @@ public void setSMaxAge(Duration sMaxAge) {
459458
this.sMaxAge = sMaxAge;
460459
}
461460

462-
public CacheControl toHttpCacheControl() {
463-
CacheControl cacheControl = createCacheControl();
461+
public org.springframework.http.CacheControl toHttpCacheControl() {
462+
org.springframework.http.CacheControl cacheControl = createCacheControl();
464463
callIfTrue(this.mustRevalidate, cacheControl,
465-
CacheControl::mustRevalidate);
466-
callIfTrue(this.noTransform, cacheControl, CacheControl::noTransform);
467-
callIfTrue(this.cachePublic, cacheControl, CacheControl::cachePublic);
468-
callIfTrue(this.cachePrivate, cacheControl, CacheControl::cachePrivate);
464+
org.springframework.http.CacheControl::mustRevalidate);
465+
callIfTrue(this.noTransform, cacheControl, org.springframework.http.CacheControl::noTransform);
466+
callIfTrue(this.cachePublic, cacheControl, org.springframework.http.CacheControl::cachePublic);
467+
callIfTrue(this.cachePrivate, cacheControl, org.springframework.http.CacheControl::cachePrivate);
469468
callIfTrue(this.proxyRevalidate, cacheControl,
470-
CacheControl::proxyRevalidate);
469+
org.springframework.http.CacheControl::proxyRevalidate);
471470
if (this.staleWhileRevalidate != null) {
472471
cacheControl.staleWhileRevalidate(
473472
this.staleWhileRevalidate.getSeconds(), TimeUnit.SECONDS);
@@ -482,18 +481,18 @@ public CacheControl toHttpCacheControl() {
482481
return cacheControl;
483482
}
484483

485-
private CacheControl createCacheControl() {
484+
private org.springframework.http.CacheControl createCacheControl() {
486485
if (Boolean.TRUE.equals(this.noStore)) {
487-
return CacheControl.noStore();
486+
return org.springframework.http.CacheControl.noStore();
488487
}
489488
if (Boolean.TRUE.equals(this.noCache)) {
490-
return CacheControl.noCache();
489+
return org.springframework.http.CacheControl.noCache();
491490
}
492491
if (this.maxAge != null) {
493-
return CacheControl.maxAge(this.maxAge.getSeconds(),
492+
return org.springframework.http.CacheControl.maxAge(this.maxAge.getSeconds(),
494493
TimeUnit.SECONDS);
495494
}
496-
return CacheControl.empty();
495+
return org.springframework.http.CacheControl.empty();
497496
}
498497

499498
private <T> void callIfTrue(Boolean property, T instance, Consumer<T> call) {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
307307
return;
308308
}
309309
Duration cachePeriod = this.resourceProperties.getCache().getPeriod();
310-
CacheControl cacheControl = this.resourceProperties.getCache().getControl()
310+
CacheControl cacheControl = this.resourceProperties.getCache().getCacheControl()
311311
.toHttpCacheControl();
312312
if (!registry.hasMappingForPattern("/webjars/**")) {
313313
customizeResourceHandlerRegistration(

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import org.springframework.boot.autoconfigure.web.ResourceProperties.Cache;
2424
import org.springframework.boot.testsupport.assertj.Matched;
25-
import org.springframework.http.CacheControl;
2625

2726
import static org.assertj.core.api.Assertions.assertThat;
2827
import static org.hamcrest.CoreMatchers.endsWith;
@@ -74,14 +73,14 @@ public void customStaticLocationsAreNormalizedToEndWithTrailingSlash() {
7473

7574
@Test
7675
public void emptyCacheControl() {
77-
CacheControl cacheControl = this.properties.getCache().getControl()
76+
org.springframework.http.CacheControl cacheControl = this.properties.getCache().getCacheControl()
7877
.toHttpCacheControl();
7978
assertThat(cacheControl.getHeaderValue()).isNull();
8079
}
8180

8281
@Test
8382
public void cacheControlAllPropertiesSet() {
84-
Cache.Control properties = this.properties.getCache().getControl();
83+
Cache.CacheControl properties = this.properties.getCache().getCacheControl();
8584
properties.setMaxAge(Duration.ofSeconds(4));
8685
properties.setCachePrivate(true);
8786
properties.setCachePublic(true);
@@ -91,18 +90,18 @@ public void cacheControlAllPropertiesSet() {
9190
properties.setSMaxAge(Duration.ofSeconds(5));
9291
properties.setStaleIfError(Duration.ofSeconds(6));
9392
properties.setStaleWhileRevalidate(Duration.ofSeconds(7));
94-
CacheControl cacheControl = properties.toHttpCacheControl();
93+
org.springframework.http.CacheControl cacheControl = properties.toHttpCacheControl();
9594
assertThat(cacheControl.getHeaderValue()).isEqualTo(
9695
"max-age=4, must-revalidate, no-transform, public, private, proxy-revalidate,"
9796
+ " s-maxage=5, stale-if-error=6, stale-while-revalidate=7");
9897
}
9998

10099
@Test
101100
public void invalidCacheControlCombination() {
102-
Cache.Control properties = this.properties.getCache().getControl();
101+
Cache.CacheControl properties = this.properties.getCache().getCacheControl();
103102
properties.setMaxAge(Duration.ofSeconds(4));
104103
properties.setNoStore(true);
105-
CacheControl cacheControl = properties.toHttpCacheControl();
104+
org.springframework.http.CacheControl cacheControl = properties.toHttpCacheControl();
106105
assertThat(cacheControl.getHeaderValue()).isEqualTo("no-store");
107106
}
108107

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,8 @@ private void assertCachePeriod(AssertableWebApplicationContext context) {
733733
@Test
734734
public void cacheControl() throws Exception {
735735
this.contextRunner
736-
.withPropertyValues("spring.resources.cache.control.max-age:5",
737-
"spring.resources.cache.control.proxy-revalidate:true")
736+
.withPropertyValues("spring.resources.cache.cachecontrol.max-age:5",
737+
"spring.resources.cache.cachecontrol.proxy-revalidate:true")
738738
.run((context) -> assertCacheControl(context));
739739
}
740740

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -399,17 +399,17 @@ content into your application. Rather, pick only the properties that you need.
399399
400400
# SPRING RESOURCES HANDLING ({sc-spring-boot-autoconfigure}/web/ResourceProperties.{sc-ext}[ResourceProperties])
401401
spring.resources.add-mappings=true # Whether to enable default resource handling.
402-
spring.resources.cache.control.max-age= # Maximum time the response should be cached, in seconds if no duration suffix is not specified.
403-
spring.resources.cache.control.no-cache= # Indicate that the cached response can be reused only if re-validated with the server.
404-
spring.resources.cache.control.no-store= # Indicate to not cache the response in any case.
405-
spring.resources.cache.control.must-revalidate= # Indicate that once it has become stale, a cache must not use the response without re-validating it with the server.
406-
spring.resources.cache.control.no-transform= # Indicate intermediaries (caches and others) that they should not transform the response content.
407-
spring.resources.cache.control.cache-public= # Indicate that any cache may store the response.
408-
spring.resources.cache.control.cache-private= # Indicate that the response message is intended for a single user and must not be stored by a shared cache.
409-
spring.resources.cache.control.proxy-revalidate= # Same meaning as the "must-revalidate" directive, except that it does not apply to private caches.
410-
spring.resources.cache.control.stale-while-revalidate= # Maximum time the response can be served after it becomes stale, in seconds if no duration suffix is not specified.
411-
spring.resources.cache.control.stale-if-error= # Maximum time the response may be used when errors are encountered, in seconds if no duration suffix is not specified.
412-
spring.resources.cache.control.s-max-age= # Maximum time the response should be cached by shared caches, in seconds if no duration suffix is not specified.
402+
spring.resources.cache.cachecontrol.max-age= # Maximum time the response should be cached, in seconds if no duration suffix is not specified.
403+
spring.resources.cache.cachecontrol.no-cache= # Indicate that the cached response can be reused only if re-validated with the server.
404+
spring.resources.cache.cachecontrol.no-store= # Indicate to not cache the response in any case.
405+
spring.resources.cache.cachecontrol.must-revalidate= # Indicate that once it has become stale, a cache must not use the response without re-validating it with the server.
406+
spring.resources.cache.cachecontrol.no-transform= # Indicate intermediaries (caches and others) that they should not transform the response content.
407+
spring.resources.cache.cachecontrol.cache-public= # Indicate that any cache may store the response.
408+
spring.resources.cache.cachecontrol.cache-private= # Indicate that the response message is intended for a single user and must not be stored by a shared cache.
409+
spring.resources.cache.cachecontrol.proxy-revalidate= # Same meaning as the "must-revalidate" directive, except that it does not apply to private caches.
410+
spring.resources.cache.cachecontrol.stale-while-revalidate= # Maximum time the response can be served after it becomes stale, in seconds if no duration suffix is not specified.
411+
spring.resources.cache.cachecontrol.stale-if-error= # Maximum time the response may be used when errors are encountered, in seconds if no duration suffix is not specified.
412+
spring.resources.cache.cachecontrol.s-max-age= # Maximum time the response should be cached by shared caches, in seconds if no duration suffix is not specified.
413413
spring.resources.cache.period= # Cache period for the resources served by the resource handler. If a duration suffix is not specified, seconds will be used.
414414
spring.resources.chain.cache=true # Whether to enable caching in the Resource chain.
415415
spring.resources.chain.enabled= # Whether to enable the Spring Resource Handling chain. By default, disabled unless at least one strategy has been enabled.

0 commit comments

Comments
 (0)