Browse Source

Document default value of server.tomcat.resource.cache-ttl

Closes gh-47252
pull/47304/head
Stéphane Nicoll 3 months ago
parent
commit
6f18f1b881
  1. 2
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java
  2. 16
      spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java

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

@ -1016,7 +1016,7 @@ public class ServerProperties { @@ -1016,7 +1016,7 @@ public class ServerProperties {
/**
* Time-to-live of the static resource cache.
*/
private Duration cacheTtl;
private Duration cacheTtl = Duration.ofSeconds(5);
public boolean isAllowCaching() {
return this.allowCaching;

16
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package org.springframework.boot.autoconfigure.web.embedded;
import java.time.Duration;
import java.util.Locale;
import java.util.function.Consumer;
@ -314,6 +315,19 @@ class TomcatWebServerFactoryCustomizerTests { @@ -314,6 +315,19 @@ class TomcatWebServerFactoryCustomizerTests {
assertThat(remoteIpValve.getTrustedProxies()).isEqualTo("proxy1|proxy2");
}
@Test
void resourceCacheMatchesDefault() {
ServerProperties properties = new ServerProperties();
customizeAndRunServer((server) -> {
Tomcat tomcat = server.getTomcat();
Context context = (Context) tomcat.getHost().findChildren()[0];
assertThat(properties.getTomcat().getResource().isAllowCaching())
.isEqualTo(context.getResources().isCachingAllowed());
assertThat(properties.getTomcat().getResource().getCacheTtl())
.isEqualTo(Duration.ofMillis(context.getResources().getCacheTtl()));
});
}
@Test
void customStaticResourceAllowCaching() {
bind("server.tomcat.resource.allow-caching=false");
@ -326,7 +340,7 @@ class TomcatWebServerFactoryCustomizerTests { @@ -326,7 +340,7 @@ class TomcatWebServerFactoryCustomizerTests {
@Test
void customStaticResourceCacheTtl() {
bind("server.tomcat.resource.cache-ttl=10000");
bind("server.tomcat.resource.cache-ttl=10s");
customizeAndRunServer((server) -> {
Tomcat tomcat = server.getTomcat();
Context context = (Context) tomcat.getHost().findChildren()[0];

Loading…
Cancel
Save