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