Skip to content

Commit 35bceee

Browse files
committed
Merge branch '3.5.x'
Closes gh-47254
2 parents 2e8eb52 + 209d4ab commit 35bceee

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

module/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/autoconfigure/TomcatServerProperties.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ public static class Resource {
702702
/**
703703
* Time-to-live of the static resource cache.
704704
*/
705-
private @Nullable Duration cacheTtl;
705+
private Duration cacheTtl = Duration.ofSeconds(5);
706706

707707
public boolean isAllowCaching() {
708708
return this.allowCaching;
@@ -720,11 +720,11 @@ public void setCacheMaxSize(DataSize cacheMaxSize) {
720720
this.cacheMaxSize = cacheMaxSize;
721721
}
722722

723-
public @Nullable Duration getCacheTtl() {
723+
public Duration getCacheTtl() {
724724
return this.cacheTtl;
725725
}
726726

727-
public void setCacheTtl(@Nullable Duration cacheTtl) {
727+
public void setCacheTtl(Duration cacheTtl) {
728728
this.cacheTtl = cacheTtl;
729729
}
730730

module/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/autoconfigure/TomcatWebServerFactoryCustomizer.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,8 @@ private void customizeStaticResources(ConfigurableTomcatWebServerFactory factory
380380
factory.addContextCustomizers((context) -> context.addLifecycleListener((event) -> {
381381
if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
382382
context.getResources().setCachingAllowed(resource.isAllowCaching());
383-
long cacheMaxSize = resource.getCacheMaxSize().toKilobytes();
384-
context.getResources().setCacheMaxSize(cacheMaxSize);
385-
if (resource.getCacheTtl() != null) {
386-
long ttl = resource.getCacheTtl().toMillis();
387-
context.getResources().setCacheTtl(ttl);
388-
}
383+
context.getResources().setCacheMaxSize(resource.getCacheMaxSize().toKilobytes());
384+
context.getResources().setCacheTtl(resource.getCacheTtl().toMillis());
389385
}
390386
}));
391387
}

module/spring-boot-tomcat/src/test/java/org/springframework/boot/tomcat/autoconfigure/TomcatWebServerFactoryCustomizerTests.java

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

1717
package org.springframework.boot.tomcat.autoconfigure;
1818

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

@@ -331,6 +332,8 @@ void resourceCacheMatchesDefault() {
331332
assertThat(properties.getResource().isAllowCaching()).isEqualTo(context.getResources().isCachingAllowed());
332333
assertThat(properties.getResource().getCacheMaxSize())
333334
.isEqualTo(DataSize.ofKilobytes(context.getResources().getCacheMaxSize()));
335+
assertThat(properties.getResource().getCacheTtl())
336+
.isEqualTo(Duration.ofMillis(context.getResources().getCacheTtl()));
334337
});
335338
}
336339

@@ -356,7 +359,7 @@ void customStaticResourceCacheMaxSize() {
356359

357360
@Test
358361
void customStaticResourceCacheTtl() {
359-
bind("server.tomcat.resource.cache-ttl=10000");
362+
bind("server.tomcat.resource.cache-ttl=10s");
360363
customizeAndRunServer((server) -> {
361364
Tomcat tomcat = server.getTomcat();
362365
Context context = (Context) tomcat.getHost().findChildren()[0];

0 commit comments

Comments
 (0)