Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,11 @@ public static class Resource {
*/
private boolean allowCaching = true;

/**
* Maximum size of the static resource cache.
*/
private @Nullable DataSize cacheMaxSize;

/**
* Time-to-live of the static resource cache.
*/
Expand All @@ -707,6 +712,14 @@ public void setAllowCaching(boolean allowCaching) {
this.allowCaching = allowCaching;
}

public @Nullable DataSize getCacheMaxSize() {
return this.cacheMaxSize;
}

public void setCacheMaxSize(@Nullable DataSize cacheMaxSize) {
this.cacheMaxSize = cacheMaxSize;
}

public @Nullable Duration getCacheTtl() {
return this.cacheTtl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ private void customizeStaticResources(ConfigurableTomcatWebServerFactory factory
long ttl = resource.getCacheTtl().toMillis();
context.getResources().setCacheTtl(ttl);
}
if (resource.getCacheMaxSize() != null) {
long cacheMaxSize = resource.getCacheMaxSize().toKilobytes();
context.getResources().setCacheMaxSize(cacheMaxSize);
}
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ void customStaticResourceAllowCaching() {
});
}

@Test
void customStaticResourceCacheMaxSize() {
bind("server.tomcat.resource.cache-max-size=4096KB");
customizeAndRunServer((server) -> {
Tomcat tomcat = server.getTomcat();
Context context = (Context) tomcat.getHost().findChildren()[0];
assertThat(context.getResources().getCacheMaxSize()).isEqualTo(4096L);
});
}

@Test
void customStaticResourceCacheTtl() {
bind("server.tomcat.resource.cache-ttl=10000");
Expand Down