mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-22 17:35:22 +00:00
Polish contribution
See gh-47229
This commit is contained in:
+3
-3
@@ -697,7 +697,7 @@ public class TomcatServerProperties {
|
||||
/**
|
||||
* Maximum size of the static resource cache.
|
||||
*/
|
||||
private @Nullable DataSize cacheMaxSize;
|
||||
private DataSize cacheMaxSize = DataSize.ofMegabytes(10);
|
||||
|
||||
/**
|
||||
* Time-to-live of the static resource cache.
|
||||
@@ -712,11 +712,11 @@ public class TomcatServerProperties {
|
||||
this.allowCaching = allowCaching;
|
||||
}
|
||||
|
||||
public @Nullable DataSize getCacheMaxSize() {
|
||||
public DataSize getCacheMaxSize() {
|
||||
return this.cacheMaxSize;
|
||||
}
|
||||
|
||||
public void setCacheMaxSize(@Nullable DataSize cacheMaxSize) {
|
||||
public void setCacheMaxSize(DataSize cacheMaxSize) {
|
||||
this.cacheMaxSize = cacheMaxSize;
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -380,14 +380,12 @@ 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);
|
||||
}
|
||||
if (resource.getCacheMaxSize() != null) {
|
||||
long cacheMaxSize = resource.getCacheMaxSize().toKilobytes();
|
||||
context.getResources().setCacheMaxSize(cacheMaxSize);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
+13
-1
@@ -322,6 +322,18 @@ class TomcatWebServerFactoryCustomizerTests {
|
||||
assertThat(remoteIpValve.getTrustedProxies()).isEqualTo("proxy1|proxy2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceCacheMatchesDefault() {
|
||||
TomcatServerProperties properties = new TomcatServerProperties();
|
||||
customizeAndRunServer((server) -> {
|
||||
Tomcat tomcat = server.getTomcat();
|
||||
Context context = (Context) tomcat.getHost().findChildren()[0];
|
||||
assertThat(properties.getResource().isAllowCaching()).isEqualTo(context.getResources().isCachingAllowed());
|
||||
assertThat(properties.getResource().getCacheMaxSize())
|
||||
.isEqualTo(DataSize.ofKilobytes(context.getResources().getCacheMaxSize()));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void customStaticResourceAllowCaching() {
|
||||
bind("server.tomcat.resource.allow-caching=false");
|
||||
@@ -334,7 +346,7 @@ class TomcatWebServerFactoryCustomizerTests {
|
||||
|
||||
@Test
|
||||
void customStaticResourceCacheMaxSize() {
|
||||
bind("server.tomcat.resource.cache-max-size=4096KB");
|
||||
bind("server.tomcat.resource.cache-max-size=4MB");
|
||||
customizeAndRunServer((server) -> {
|
||||
Tomcat tomcat = server.getTomcat();
|
||||
Context context = (Context) tomcat.getHost().findChildren()[0];
|
||||
|
||||
Reference in New Issue
Block a user