From: markt Date: Fri, 26 Sep 2008 11:56:42 +0000 (+0000) Subject: Allow the maximum allowed size of a resource that is cached to be configured. The... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6fcc01396ba0399a0c0b7c6a973e824b9987a4a9;p=tomcat7.0 Allow the maximum allowed size of a resource that is cached to be configured. The default of cacheMaxSize/20 gave too high a value for large caches. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@699287 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index 719da0989..c430d0868 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -626,6 +626,12 @@ public class StandardContext /** + * Cache object max size in KB. + */ + protected int cacheObjectMaxSize = 512; // 512K + + + /** * Cache TTL in ms. */ protected int cacheTTL = 5000; @@ -789,6 +795,22 @@ public class StandardContext /** + * Return the maximum size of objects to be cached in KB. + */ + public int getCacheObjectMaxSize() { + return cacheObjectMaxSize; + } + + + /** + * Set the maximum size of objects to be placed the cache in KB. + */ + public void setCacheObjectMaxSize(int cacheObjectMaxSize) { + this.cacheObjectMaxSize = cacheObjectMaxSize; + } + + + /** * Return the "follow standard delegation model" flag used to configure * our ClassLoader. */ @@ -1830,6 +1852,8 @@ public class StandardContext ((BaseDirContext) resources).setCached(isCachingAllowed()); ((BaseDirContext) resources).setCacheTTL(getCacheTTL()); ((BaseDirContext) resources).setCacheMaxSize(getCacheMaxSize()); + ((BaseDirContext) resources).setCacheObjectMaxSize( + getCacheObjectMaxSize()); } if (resources instanceof FileDirContext) { filesystemBased = true; diff --git a/java/org/apache/catalina/core/mbeans-descriptors.xml b/java/org/apache/catalina/core/mbeans-descriptors.xml index e62ab78f3..34ddce36a 100644 --- a/java/org/apache/catalina/core/mbeans-descriptors.xml +++ b/java/org/apache/catalina/core/mbeans-descriptors.xml @@ -57,6 +57,10 @@ description="Maximum cache size in KB" type="int"/> + + diff --git a/java/org/apache/naming/resources/BaseDirContext.java b/java/org/apache/naming/resources/BaseDirContext.java index 78f3c02b1..834500109 100644 --- a/java/org/apache/naming/resources/BaseDirContext.java +++ b/java/org/apache/naming/resources/BaseDirContext.java @@ -105,11 +105,17 @@ public abstract class BaseDirContext implements DirContext { /** - * Max size of resources which will have their content cached. + * Max size of cache for resources. */ protected int cacheMaxSize = 10240; // 10 MB + /** + * Max size of resources that will be content cached. + */ + protected int cacheObjectMaxSize = 512; // 512 K + + // ------------------------------------------------------------- Properties @@ -192,6 +198,22 @@ public abstract class BaseDirContext implements DirContext { } + /** + * Return the maximum size of objects to be cached in KB. + */ + public int getCacheObjectMaxSize() { + return cacheObjectMaxSize; + } + + + /** + * Set the maximum size of objects to be placed the cache in KB. + */ + public void setCacheObjectMaxSize(int cacheObjectMaxSize) { + this.cacheObjectMaxSize = cacheObjectMaxSize; + } + + // --------------------------------------------------------- Public Methods diff --git a/java/org/apache/naming/resources/ProxyDirContext.java b/java/org/apache/naming/resources/ProxyDirContext.java index 05cb7a3e4..e75bed886 100644 --- a/java/org/apache/naming/resources/ProxyDirContext.java +++ b/java/org/apache/naming/resources/ProxyDirContext.java @@ -78,7 +78,12 @@ public class ProxyDirContext implements DirContext { } cache.setCacheMaxSize(baseDirContext.getCacheMaxSize()); cacheTTL = baseDirContext.getCacheTTL(); - cacheObjectMaxSize = baseDirContext.getCacheMaxSize() / 20; + cacheObjectMaxSize = baseDirContext.getCacheObjectMaxSize(); + // cacheObjectMaxSize must be less than cacheMaxSize + // Set a sensible limit + if (cacheObjectMaxSize > baseDirContext.getCacheMaxSize()/20) { + cacheObjectMaxSize = baseDirContext.getCacheMaxSize()/20; + } } } hostName = (String) env.get(HOST); diff --git a/webapps/docs/config/context.xml b/webapps/docs/config/context.xml index e62d94e81..404f8abb9 100644 --- a/webapps/docs/config/context.xml +++ b/webapps/docs/config/context.xml @@ -284,6 +284,14 @@ (10 megabytes).

+ +

Maximum size of the static resource that will be placed in the cache. + If not specified, the default value is 512 + (512 kilobytes). If this value is greater than + cacheMaxSize/20 it will be reduced to + cacheMaxSize/20.

+
+

Amount of time in milliseconds between cache entries revalidation. If not specified, the default value is 5000