commit
35bceeead2
|
@ -702,7 +702,7 @@ public class TomcatServerProperties {
|
|||
/**
|
||||
* Time-to-live of the static resource cache.
|
||||
*/
|
||||
private @Nullable Duration cacheTtl;
|
||||
private Duration cacheTtl = Duration.ofSeconds(5);
|
||||
|
||||
public boolean isAllowCaching() {
|
||||
return this.allowCaching;
|
||||
|
@ -720,11 +720,11 @@ public class TomcatServerProperties {
|
|||
this.cacheMaxSize = cacheMaxSize;
|
||||
}
|
||||
|
||||
public @Nullable Duration getCacheTtl() {
|
||||
public Duration getCacheTtl() {
|
||||
return this.cacheTtl;
|
||||
}
|
||||
|
||||
public void setCacheTtl(@Nullable Duration cacheTtl) {
|
||||
public void setCacheTtl(Duration cacheTtl) {
|
||||
this.cacheTtl = cacheTtl;
|
||||
}
|
||||
|
||||
|
|
|
@ -380,12 +380,8 @@ public class TomcatWebServerFactoryCustomizer
|
|||
factory.addContextCustomizers((context) -> context.addLifecycleListener((event) -> {
|
||||
if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
|
||||
context.getResources().setCachingAllowed(resource.isAllowCaching());
|
||||
long cacheMaxSize = resource.getCacheMaxSize().toKilobytes();
|
||||
context.getResources().setCacheMaxSize(cacheMaxSize);
|
||||
if (resource.getCacheTtl() != null) {
|
||||
long ttl = resource.getCacheTtl().toMillis();
|
||||
context.getResources().setCacheTtl(ttl);
|
||||
}
|
||||
context.getResources().setCacheMaxSize(resource.getCacheMaxSize().toKilobytes());
|
||||
context.getResources().setCacheTtl(resource.getCacheTtl().toMillis());
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.boot.tomcat.autoconfigure;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
@ -331,6 +332,8 @@ class TomcatWebServerFactoryCustomizerTests {
|
|||
assertThat(properties.getResource().isAllowCaching()).isEqualTo(context.getResources().isCachingAllowed());
|
||||
assertThat(properties.getResource().getCacheMaxSize())
|
||||
.isEqualTo(DataSize.ofKilobytes(context.getResources().getCacheMaxSize()));
|
||||
assertThat(properties.getResource().getCacheTtl())
|
||||
.isEqualTo(Duration.ofMillis(context.getResources().getCacheTtl()));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -356,7 +359,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…
Reference in New Issue