Commits

Anonymous committed 04ba200

Altering the cache capacity on the fly using the administrator classes wasn't working correctly.

  • Participants
  • Parent commits 121f098

Comments (0)

Files changed (5)

+OSCACHE 2.0
+-------------
+Bug fixes:
+- [CACHE-52] Fixed a problem that caused no output on Tomcat for small JSP files.
+- [CACHE-55] JMS was throwing an exception on Weblogic.
+- Altering the cache capacity on the fly using the administrator classes wasn't
+  working correctly.
+
+Improvements:
+- Minor FastCronParser speedup.
+- Made ClusterNotification constants public.
+- Dropped some of the logging levels from INFO down to DEBUG.
+
+
 OSCACHE 2.0 (beta 2)
 -------------
 New features:

File src/core/java/com/opensymphony/oscache/base/AbstractCacheAdministrator.java

  */
 package com.opensymphony.oscache.base;
 
+import com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache;
 import com.opensymphony.oscache.base.events.*;
 import com.opensymphony.oscache.base.persistence.PersistenceListener;
 import com.opensymphony.oscache.util.StringUtil;
     }
 
     /**
-     * Sets the cache capacity (number of items).
+     * Sets the cache capacity (number of items). Administrator implementations
+     * should override this method to ensure that their {@link Cache} objects
+     * are updated correctly (by calling {@link AbstractConcurrentReadCache#setMaxEntries(int)}}}.
      *
      * @param newCacheCapacity The new capacity
      */
-    public void setCacheCapacity(int newCacheCapacity) {
+    protected void setCacheCapacity(int newCacheCapacity) {
         cacheCapacity = newCacheCapacity;
     }
 

File src/core/java/com/opensymphony/oscache/base/Cache.java

     }
 
     /**
+     * Allows the capacity of the cache to be altered dynamically. Note that
+     * some cache implementations may choose to ignore this setting (eg the
+     * {@link UnlimitedCache} ignores this call).
+     *
+     * @param capacity the maximum number of items to hold in the cache.
+     */
+    public void setCapacity(int capacity) {
+        cacheMap.setMaxEntries(capacity);
+    }
+
+    /**
      * Checks if the cache was flushed more recently than the CacheEntry provided.
      * Used to determine whether to refresh the particular CacheEntry.
      *

File src/core/java/com/opensymphony/oscache/general/GeneralCacheAdministrator.java

     }
 
     /**
+     * Sets the cache capacity (number of items). If the cache contains
+     * more than <code>capacity</code> items then items will be removed
+     * to bring the cache back down to the new size.
+     *
+     * @param capacity The new capacity of the cache
+     */
+    public void setCacheCapacity(int capacity) {
+        super.setCacheCapacity(capacity);
+        getCache().setCapacity(capacity);
+    }
+
+    /**
      * Creates a cache in this admin
      *
      * @return The new cache

File src/core/java/com/opensymphony/oscache/web/ServletCacheAdministrator.java

                 } catch (Exception e) {
                     // Ignore query string
                 }
-
-                generatedKey = null;
             }
         }
 
     }
 
     /**
+     * Sets the cache capacity (number of items). If the cache contains
+     * more than <code>capacity</code> items then items will be removed
+     * to bring the cache back down to the new size.
+     *
+     * @param scope The cache scope
+     * @param request The servlet request
+     * @param capacity The new capacity
+     */
+    public void setCacheCapacity(int scope, HttpServletRequest request, int capacity) {
+        setCacheCapacity(capacity);
+        getCache(request, scope).setCapacity(capacity);
+    }
+
+    /**
      * Unregister a listener for Cache Map events.
      *
      * @param listener  The object that currently listens to events.