jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r474246 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state: Cache.java CacheManager.java MLRUItemStateCache.java
Date Mon, 13 Nov 2006 10:55:13 GMT
Author: stefan
Date: Mon Nov 13 02:55:13 2006
New Revision: 474246

URL: http://svn.apache.org/viewvc?view=rev&rev=474246
Log:
reverting changes from r471800 since it caused a considerable performance degradation 

Removed:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/Cache.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/CacheManager.java
Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java?view=diff&rev=474246&r1=474245&r2=474246
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java
Mon Nov 13 02:55:13 2006
@@ -34,7 +34,7 @@
  * cache uses a rough estimate of the memory consuption of the cache item
  * states for calculating the maximum number of entries.
  */
-public class MLRUItemStateCache implements ItemStateCache, Cache {
+public class MLRUItemStateCache implements ItemStateCache {
     /** Logger instance */
     private static Logger log = LoggerFactory.getLogger(LRUItemStateCache.class);
 
@@ -45,14 +45,11 @@
     private long totalMem;
 
     /** the maximum of memory the cache may use */
-    private long maxMem;
+    private final long maxMem;
 
     /** the number of writes */
     private long numWrites = 0;
 
-    /** the access count */
-    private long accessCount = 0;
-
     /**
      * A cache for <code>ItemState</code> instances
      */
@@ -74,7 +71,6 @@
      */
     public MLRUItemStateCache(int maxMem) {
         this.maxMem = maxMem;
-        CacheManager.getInstance().add(this);
     }
 
     //-------------------------------------------------------< ItemStateCache >
@@ -92,7 +88,6 @@
      */
     public ItemState retrieve(ItemId id) {
         synchronized (cache) {
-            touch();
             Entry entry = (Entry) cache.remove(id);
             if (entry != null) {
                 // 'touch' item, by adding at end of list
@@ -109,7 +104,6 @@
      */
     public void update(ItemId id) {
         synchronized (cache) {
-            touch();
             Entry entry = (Entry) cache.get(id);
             if (entry != null) {
                 totalMem -= entry.size;
@@ -124,7 +118,6 @@
      */
     public void cache(ItemState state) {
         synchronized (cache) {
-            touch();
             ItemId id = state.getId();
             if (cache.containsKey(id)) {
                 log.warn("overwriting cached entry " + id);
@@ -133,27 +126,22 @@
             Entry entry = new Entry(state);
             cache.put(id, entry);
             totalMem += entry.size;
-            shrinkIfRequired();
+            // remove items, if too many
+            while (totalMem > maxMem) {
+                id = (ItemId) cache.firstKey();
+                evict(id);
+            }
             if (numWrites++%10000 == 0 && log.isDebugEnabled()) {
                 log.info(this + " size=" + cache.size() + ", " + totalMem + "/" + maxMem);
             }
         }
     }
 
-    private void shrinkIfRequired() {
-        // remove items, if too many
-        while (totalMem > maxMem) {
-            ItemId id = (ItemId) cache.firstKey();
-            evict(id);
-        }
-    }
-
     /**
      * {@inheritDoc}
      */
     public void evict(ItemId id) {
         synchronized (cache) {
-            touch();
             Entry entry = (Entry) cache.remove(id);
             if (entry != null) {
                 totalMem -= entry.size;
@@ -210,59 +198,6 @@
                 list.add(entry.state);
             }
             return list;
-        }
-    }
-
-    private void touch() {
-        accessCount++;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public long getAccessCount() {
-        return accessCount;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public long getMaxMemorySize() {
-        return maxMem;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public long getMemoryUsed() {
-        synchronized (cache) {
-            totalMem = 0;
-            Iterator iter = cache.values().iterator();
-            while (iter.hasNext()) {
-                Entry entry = (Entry) iter.next();
-                entry.recalc();
-                totalMem += entry.size;
-            }
-        }
-        return totalMem;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void resetAccessCount() {
-        synchronized (cache) {
-            accessCount = 0;
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void setMaxMemorySize(long size) {
-        synchronized (cache) {
-            this.maxMem = size;
-            shrinkIfRequired();
         }
     }
 



Mime
View raw message