You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ra...@apache.org on 2006/05/23 01:50:15 UTC

svn commit: r408791 - /xmlbeans/branches/1.x/src/xmlstore/org/apache/xmlbeans/impl/store/Path.java

Author: radup
Date: Mon May 22 16:50:14 2006
New Revision: 408791

URL: http://svn.apache.org/viewvc?rev=408791&view=rev
Log:
Put a cap on the maximum number of paths that can be cached.

Modified:
    xmlbeans/branches/1.x/src/xmlstore/org/apache/xmlbeans/impl/store/Path.java

Modified: xmlbeans/branches/1.x/src/xmlstore/org/apache/xmlbeans/impl/store/Path.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/1.x/src/xmlstore/org/apache/xmlbeans/impl/store/Path.java?rev=408791&r1=408790&r2=408791&view=diff
==============================================================================
--- xmlbeans/branches/1.x/src/xmlstore/org/apache/xmlbeans/impl/store/Path.java (original)
+++ xmlbeans/branches/1.x/src/xmlstore/org/apache/xmlbeans/impl/store/Path.java Mon May 22 16:50:14 2006
@@ -23,8 +23,9 @@
 import org.apache.xmlbeans.impl.store.Cursor.PathEngine;
 import org.apache.xmlbeans.impl.store.Cursor.Selections;
 
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Represents a precompiled path expression
@@ -559,7 +560,32 @@
         }
     }
 
-    private static HashMap _xqrlPathCache = new HashMap();
-    private static HashMap _xbeanPathCache = new HashMap();
-    private static HashMap _xqrlQueryCache = new HashMap();
+    private static Map _xqrlPathCache = new CacheMap();
+    private static Map _xbeanPathCache = new CacheMap();
+    private static Map _xqrlQueryCache = new CacheMap();
+
+    private static class CacheMap extends LinkedHashMap
+    {
+        private static final String XPATH_CACHE_SIZE = "xmlbean.xpathCacheSize";
+
+        private static int MAX_ENTRIES = -1;
+
+        CacheMap()
+        {
+            String size = null;
+            if ((size = System.getProperty(XPATH_CACHE_SIZE)) != null)
+                try 
+                {
+                    MAX_ENTRIES = Integer.parseInt(size);
+                }
+                catch (Exception e)
+                {
+                }
+        }
+
+        protected boolean removeEldestEntry(Map.Entry eldest)
+        {
+            return MAX_ENTRIES > 0 && size() > MAX_ENTRIES;
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org