tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1401275 - /tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Cache.java
Date Tue, 23 Oct 2012 12:43:00 GMT
Author: markt
Date: Tue Oct 23 12:42:59 2012
New Revision: 1401275

URL: http://svn.apache.org/viewvc?rev=1401275&view=rev
Log:
When removing an item from the cache, only reduce the current cache size of the item was added
to the cache.
Provide conversions (bytes/kilobytes) for maxCacheObjectSize

Modified:
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Cache.java

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Cache.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Cache.java?rev=1401275&r1=1401274&r2=1401275&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Cache.java (original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Cache.java Tue Oct
23 12:42:59 2012
@@ -62,7 +62,7 @@ public class Cache {
         CachedResource cacheEntry = resourceCache.get(path);
 
         if (cacheEntry != null && !cacheEntry.validate()) {
-            removeCacheEntry(path);
+            removeCacheEntry(path, true);
             cacheEntry = null;
         }
 
@@ -77,7 +77,8 @@ public class Cache {
                 cacheEntry = newCacheEntry;
                 cacheEntry.validate();
                 if (newCacheEntry.getContentLength() > getMaxObjectSize()) {
-                    removeCacheEntry(path);
+                    // Cache size has not been updated at this point
+                    removeCacheEntry(path, false);
                     return newCacheEntry;
                 }
 
@@ -100,7 +101,7 @@ public class Cache {
                     if (newSize > maxSize) {
                         // Unable to create sufficient space for this resource
                         // Remove it from the cache
-                        removeCacheEntry(path);
+                        removeCacheEntry(path, true);
                         log.warn(sm.getString("cache.addFail"));
                     }
                 }
@@ -151,7 +152,7 @@ public class Cache {
             }
 
             // Remove the entry from the cache
-            removeCacheEntry(resource.getWebappPath());
+            removeCacheEntry(resource.getWebappPath(), true);
 
             newSize = size.get();
         }
@@ -159,11 +160,11 @@ public class Cache {
         return newSize;
     }
 
-    private void removeCacheEntry(String path) {
+    private void removeCacheEntry(String path, boolean updateSize) {
         // With concurrent calls for the same path, the entry is only removed
-        // once and the cache size is only updated once.
+        // once and the cache size is only updated (if required) once.
         CachedResource cachedResource = resourceCache.remove(path);
-        if (cachedResource != null) {
+        if (cachedResource != null && updateSize) {
             long delta =
                     0 - CACHE_ENTRY_SIZE - cachedResource.getContentLength();
             size.addAndGet(delta);
@@ -190,11 +191,13 @@ public class Cache {
 
 
     public void setMaxObjectSize(long maxObjectSize) {
-        this.maxObjectSize = maxObjectSize;
+        // Internally bytes, externally kilobytes
+        this.maxObjectSize = maxObjectSize * 1024;
     }
 
     public long getMaxObjectSize() {
-        return maxObjectSize;
+        // Internally bytes, externally kilobytes
+        return maxObjectSize / 1024;
     }
 
     private static class EvictionOrder implements Comparator<CachedResource> {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message