Allow the maximum allowed size of a resource that is cached to be configured. The...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 26 Sep 2008 11:56:42 +0000 (11:56 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 26 Sep 2008 11:56:42 +0000 (11:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@699287 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/core/StandardContext.java
java/org/apache/catalina/core/mbeans-descriptors.xml
java/org/apache/naming/resources/BaseDirContext.java
java/org/apache/naming/resources/ProxyDirContext.java
webapps/docs/config/context.xml

index 719da09..c430d08 100644 (file)
@@ -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;
index e62ab78..34ddce3 100644 (file)
                description="Maximum cache size in KB"
                type="int"/>
       
+    <attribute name="cacheObjectMaxSize"
+               description="Maximum cached object size in KB"
+               type="int"/>
+      
     <attribute name="cacheTTL"
                description="Time interval in ms between cache refeshes"
                type="int"/>
index 78f3c02..8345001 100644 (file)
@@ -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
 
 
index 05cb7a3..e75bed8 100644 (file)
@@ -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);
index e62d94e..404f8ab 100644 (file)
         (10 megabytes).</p>
       </attribute>
 
+      <attribute name="cacheObjectMaxSize" required="false">
+        <p>Maximum size of the static resource that will be placed in the cache.
+        If not specified, the default value is <code>512</code>
+        (512 kilobytes). If this value is greater than
+        <code>cacheMaxSize/20</code> it will be reduced to
+        <code>cacheMaxSize/20</code>.</p>
+      </attribute>
+
       <attribute name="cacheTTL" required="false">
         <p>Amount of time in milliseconds between cache entries revalidation.
         If not specified, the default value is <code>5000</code>