Skip to content

Commit 6f18f1b

Browse files
committed
Document default value of server.tomcat.resource.cache-ttl
Closes gh-47252
1 parent a9319d6 commit 6f18f1b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ public static class Resource {
10161016
/**
10171017
* Time-to-live of the static resource cache.
10181018
*/
1019-
private Duration cacheTtl;
1019+
private Duration cacheTtl = Duration.ofSeconds(5);
10201020

10211021
public boolean isAllowCaching() {
10221022
return this.allowCaching;

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.web.embedded;
1818

19+
import java.time.Duration;
1920
import java.util.Locale;
2021
import java.util.function.Consumer;
2122

@@ -314,6 +315,19 @@ void customRemoteIpValve() {
314315
assertThat(remoteIpValve.getTrustedProxies()).isEqualTo("proxy1|proxy2");
315316
}
316317

318+
@Test
319+
void resourceCacheMatchesDefault() {
320+
ServerProperties properties = new ServerProperties();
321+
customizeAndRunServer((server) -> {
322+
Tomcat tomcat = server.getTomcat();
323+
Context context = (Context) tomcat.getHost().findChildren()[0];
324+
assertThat(properties.getTomcat().getResource().isAllowCaching())
325+
.isEqualTo(context.getResources().isCachingAllowed());
326+
assertThat(properties.getTomcat().getResource().getCacheTtl())
327+
.isEqualTo(Duration.ofMillis(context.getResources().getCacheTtl()));
328+
});
329+
}
330+
317331
@Test
318332
void customStaticResourceAllowCaching() {
319333
bind("server.tomcat.resource.allow-caching=false");
@@ -326,7 +340,7 @@ void customStaticResourceAllowCaching() {
326340

327341
@Test
328342
void customStaticResourceCacheTtl() {
329-
bind("server.tomcat.resource.cache-ttl=10000");
343+
bind("server.tomcat.resource.cache-ttl=10s");
330344
customizeAndRunServer((server) -> {
331345
Tomcat tomcat = server.getTomcat();
332346
Context context = (Context) tomcat.getHost().findChildren()[0];

0 commit comments

Comments
 (0)