jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1429816 - /jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java
Date Mon, 07 Jan 2013 14:39:56 GMT
Author: angela
Date: Mon Jan  7 14:39:55 2013
New Revision: 1429816

URL: http://svn.apache.org/viewvc?rev=1429816&view=rev
Log:
JCR-3305 : spi2davex.RepositoryServiceImpl -> idUriCache raises until heap overflow  (patch
by Alexander Muthmann applied with minor modifications)

Modified:
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java?rev=1429816&r1=1429815&r2=1429816&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java
Mon Jan  7 14:39:55 2013
@@ -16,27 +16,41 @@
  */
 package org.apache.jackrabbit.spi2dav;
 
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.apache.jackrabbit.spi.ItemId;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.jackrabbit.spi.ItemId;
-
-import java.util.Map;
-import java.util.HashMap;
 
 /**
  * <code>IdURICache</code>...
  */
 class IdURICache {
-
     private static Logger log = LoggerFactory.getLogger(IdURICache.class);
 
-    private final String workspaceUri;
+    /**
+     * @see <a href="https://issues.apache.org/jira/browse/JCR-3305">JCR-3305</a>:
limit cache size
+     */
+    private static final int CACHESIZE = 10000;
 
-    private Map<ItemId, String> idToUriCache = new HashMap<ItemId, String>();
-    private Map<String, ItemId> uriToIdCache = new HashMap<String, ItemId>();
+    private final String workspaceUri;
+    private Map<ItemId, String> idToUriCache;
+    private Map<String, ItemId> uriToIdCache;
 
     IdURICache(String workspaceUri) {
         this.workspaceUri = workspaceUri;
+        idToUriCache = new LinkedHashMap<ItemId, String>(CACHESIZE, 1) {
+            @Override
+            protected boolean removeEldestEntry(Map.Entry<ItemId, String> eldest) {
+                return this.size() > CACHESIZE;
+            }
+        };
+        uriToIdCache = new LinkedHashMap<String, ItemId>(CACHESIZE, 1) {
+            @Override
+            protected boolean removeEldestEntry(Map.Entry<String, ItemId> eldest) {
+                return this.size() > CACHESIZE;
+            }
+        };
     }
 
     public ItemId getItemId(String uri) {



Mime
View raw message