Rename spring.cache.control to spring.cache.cachecontrol

Closes #11090
pull/11202/head
Brian Clozel 7 years ago
parent 55f7b3a535
commit e3c3bb0076

@ -23,7 +23,6 @@ import java.util.function.Consumer;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit; import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.http.CacheControl;
/** /**
* Properties used to configure resource handling. * Properties used to configure resource handling.
@ -275,7 +274,7 @@ public class ResourceProperties {
/** /**
* Cache period for the resources served by the resource handler. If a duration * Cache period for the resources served by the resource handler. If a duration
* suffix is not specified, seconds will be used. Can be overridden by the * suffix is not specified, seconds will be used. Can be overridden by the
* 'spring.resources.cache.control' properties. * 'spring.resources.cache.cachecontrol' properties.
*/ */
@DefaultDurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration period; private Duration period;
@ -284,7 +283,7 @@ public class ResourceProperties {
* Cache control HTTP headers, only allows valid directive combinations. Overrides * Cache control HTTP headers, only allows valid directive combinations. Overrides
* the 'spring.resources.cache.period' property. * the 'spring.resources.cache.period' property.
*/ */
private final Control control = new Control(); private final CacheControl cacheControl = new CacheControl();
public Duration getPeriod() { public Duration getPeriod() {
return this.period; return this.period;
@ -294,14 +293,14 @@ public class ResourceProperties {
this.period = period; this.period = period;
} }
public Control getControl() { public CacheControl getCacheControl() {
return this.control; return this.cacheControl;
} }
/** /**
* Cache Control HTTP header configuration. * Cache Control HTTP header configuration.
*/ */
public static class Control { public static class CacheControl {
/** /**
* Maximum time the response should be cached, in seconds if no duration * Maximum time the response should be cached, in seconds if no duration
@ -459,15 +458,15 @@ public class ResourceProperties {
this.sMaxAge = sMaxAge; this.sMaxAge = sMaxAge;
} }
public CacheControl toHttpCacheControl() { public org.springframework.http.CacheControl toHttpCacheControl() {
CacheControl cacheControl = createCacheControl(); org.springframework.http.CacheControl cacheControl = createCacheControl();
callIfTrue(this.mustRevalidate, cacheControl, callIfTrue(this.mustRevalidate, cacheControl,
CacheControl::mustRevalidate); org.springframework.http.CacheControl::mustRevalidate);
callIfTrue(this.noTransform, cacheControl, CacheControl::noTransform); callIfTrue(this.noTransform, cacheControl, org.springframework.http.CacheControl::noTransform);
callIfTrue(this.cachePublic, cacheControl, CacheControl::cachePublic); callIfTrue(this.cachePublic, cacheControl, org.springframework.http.CacheControl::cachePublic);
callIfTrue(this.cachePrivate, cacheControl, CacheControl::cachePrivate); callIfTrue(this.cachePrivate, cacheControl, org.springframework.http.CacheControl::cachePrivate);
callIfTrue(this.proxyRevalidate, cacheControl, callIfTrue(this.proxyRevalidate, cacheControl,
CacheControl::proxyRevalidate); org.springframework.http.CacheControl::proxyRevalidate);
if (this.staleWhileRevalidate != null) { if (this.staleWhileRevalidate != null) {
cacheControl.staleWhileRevalidate( cacheControl.staleWhileRevalidate(
this.staleWhileRevalidate.getSeconds(), TimeUnit.SECONDS); this.staleWhileRevalidate.getSeconds(), TimeUnit.SECONDS);
@ -482,18 +481,18 @@ public class ResourceProperties {
return cacheControl; return cacheControl;
} }
private CacheControl createCacheControl() { private org.springframework.http.CacheControl createCacheControl() {
if (Boolean.TRUE.equals(this.noStore)) { if (Boolean.TRUE.equals(this.noStore)) {
return CacheControl.noStore(); return org.springframework.http.CacheControl.noStore();
} }
if (Boolean.TRUE.equals(this.noCache)) { if (Boolean.TRUE.equals(this.noCache)) {
return CacheControl.noCache(); return org.springframework.http.CacheControl.noCache();
} }
if (this.maxAge != null) { if (this.maxAge != null) {
return CacheControl.maxAge(this.maxAge.getSeconds(), return org.springframework.http.CacheControl.maxAge(this.maxAge.getSeconds(),
TimeUnit.SECONDS); TimeUnit.SECONDS);
} }
return CacheControl.empty(); return org.springframework.http.CacheControl.empty();
} }
private <T> void callIfTrue(Boolean property, T instance, Consumer<T> call) { private <T> void callIfTrue(Boolean property, T instance, Consumer<T> call) {

@ -307,7 +307,7 @@ public class WebMvcAutoConfiguration {
return; return;
} }
Duration cachePeriod = this.resourceProperties.getCache().getPeriod(); Duration cachePeriod = this.resourceProperties.getCache().getPeriod();
CacheControl cacheControl = this.resourceProperties.getCache().getControl() CacheControl cacheControl = this.resourceProperties.getCache().getCacheControl()
.toHttpCacheControl(); .toHttpCacheControl();
if (!registry.hasMappingForPattern("/webjars/**")) { if (!registry.hasMappingForPattern("/webjars/**")) {
customizeResourceHandlerRegistration( customizeResourceHandlerRegistration(

@ -22,7 +22,6 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.web.ResourceProperties.Cache; import org.springframework.boot.autoconfigure.web.ResourceProperties.Cache;
import org.springframework.boot.testsupport.assertj.Matched; import org.springframework.boot.testsupport.assertj.Matched;
import org.springframework.http.CacheControl;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.endsWith; import static org.hamcrest.CoreMatchers.endsWith;
@ -74,14 +73,14 @@ public class ResourcePropertiesTests {
@Test @Test
public void emptyCacheControl() { public void emptyCacheControl() {
CacheControl cacheControl = this.properties.getCache().getControl() org.springframework.http.CacheControl cacheControl = this.properties.getCache().getCacheControl()
.toHttpCacheControl(); .toHttpCacheControl();
assertThat(cacheControl.getHeaderValue()).isNull(); assertThat(cacheControl.getHeaderValue()).isNull();
} }
@Test @Test
public void cacheControlAllPropertiesSet() { public void cacheControlAllPropertiesSet() {
Cache.Control properties = this.properties.getCache().getControl(); Cache.CacheControl properties = this.properties.getCache().getCacheControl();
properties.setMaxAge(Duration.ofSeconds(4)); properties.setMaxAge(Duration.ofSeconds(4));
properties.setCachePrivate(true); properties.setCachePrivate(true);
properties.setCachePublic(true); properties.setCachePublic(true);
@ -91,7 +90,7 @@ public class ResourcePropertiesTests {
properties.setSMaxAge(Duration.ofSeconds(5)); properties.setSMaxAge(Duration.ofSeconds(5));
properties.setStaleIfError(Duration.ofSeconds(6)); properties.setStaleIfError(Duration.ofSeconds(6));
properties.setStaleWhileRevalidate(Duration.ofSeconds(7)); properties.setStaleWhileRevalidate(Duration.ofSeconds(7));
CacheControl cacheControl = properties.toHttpCacheControl(); org.springframework.http.CacheControl cacheControl = properties.toHttpCacheControl();
assertThat(cacheControl.getHeaderValue()).isEqualTo( assertThat(cacheControl.getHeaderValue()).isEqualTo(
"max-age=4, must-revalidate, no-transform, public, private, proxy-revalidate," "max-age=4, must-revalidate, no-transform, public, private, proxy-revalidate,"
+ " s-maxage=5, stale-if-error=6, stale-while-revalidate=7"); + " s-maxage=5, stale-if-error=6, stale-while-revalidate=7");
@ -99,10 +98,10 @@ public class ResourcePropertiesTests {
@Test @Test
public void invalidCacheControlCombination() { public void invalidCacheControlCombination() {
Cache.Control properties = this.properties.getCache().getControl(); Cache.CacheControl properties = this.properties.getCache().getCacheControl();
properties.setMaxAge(Duration.ofSeconds(4)); properties.setMaxAge(Duration.ofSeconds(4));
properties.setNoStore(true); properties.setNoStore(true);
CacheControl cacheControl = properties.toHttpCacheControl(); org.springframework.http.CacheControl cacheControl = properties.toHttpCacheControl();
assertThat(cacheControl.getHeaderValue()).isEqualTo("no-store"); assertThat(cacheControl.getHeaderValue()).isEqualTo("no-store");
} }

@ -733,8 +733,8 @@ public class WebMvcAutoConfigurationTests {
@Test @Test
public void cacheControl() throws Exception { public void cacheControl() throws Exception {
this.contextRunner this.contextRunner
.withPropertyValues("spring.resources.cache.control.max-age:5", .withPropertyValues("spring.resources.cache.cachecontrol.max-age:5",
"spring.resources.cache.control.proxy-revalidate:true") "spring.resources.cache.cachecontrol.proxy-revalidate:true")
.run((context) -> assertCacheControl(context)); .run((context) -> assertCacheControl(context));
} }

@ -399,17 +399,17 @@ content into your application. Rather, pick only the properties that you need.
# SPRING RESOURCES HANDLING ({sc-spring-boot-autoconfigure}/web/ResourceProperties.{sc-ext}[ResourceProperties]) # SPRING RESOURCES HANDLING ({sc-spring-boot-autoconfigure}/web/ResourceProperties.{sc-ext}[ResourceProperties])
spring.resources.add-mappings=true # Whether to enable default resource handling. spring.resources.add-mappings=true # Whether to enable default resource handling.
spring.resources.cache.control.max-age= # Maximum time the response should be cached, in seconds if no duration suffix is not specified. spring.resources.cache.cachecontrol.max-age= # Maximum time the response should be cached, in seconds if no duration suffix is not specified.
spring.resources.cache.control.no-cache= # Indicate that the cached response can be reused only if re-validated with the server. spring.resources.cache.cachecontrol.no-cache= # Indicate that the cached response can be reused only if re-validated with the server.
spring.resources.cache.control.no-store= # Indicate to not cache the response in any case. spring.resources.cache.cachecontrol.no-store= # Indicate to not cache the response in any case.
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. 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.
spring.resources.cache.control.no-transform= # Indicate intermediaries (caches and others) that they should not transform the response content. spring.resources.cache.cachecontrol.no-transform= # Indicate intermediaries (caches and others) that they should not transform the response content.
spring.resources.cache.control.cache-public= # Indicate that any cache may store the response. spring.resources.cache.cachecontrol.cache-public= # Indicate that any cache may store the response.
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. 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.
spring.resources.cache.control.proxy-revalidate= # Same meaning as the "must-revalidate" directive, except that it does not apply to private caches. spring.resources.cache.cachecontrol.proxy-revalidate= # Same meaning as the "must-revalidate" directive, except that it does not apply to private caches.
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. 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.
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. 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.
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. 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.
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. 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.
spring.resources.chain.cache=true # Whether to enable caching in the Resource chain. spring.resources.chain.cache=true # Whether to enable caching in the Resource chain.
spring.resources.chain.enabled= # Whether to enable the Spring Resource Handling chain. By default, disabled unless at least one strategy has been enabled. spring.resources.chain.enabled= # Whether to enable the Spring Resource Handling chain. By default, disabled unless at least one strategy has been enabled.

Loading…
Cancel
Save