You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ce...@apache.org on 2005/04/27 00:19:40 UTC

svn commit: r164901 - in /xmlbeans/trunk/src: common/org/apache/xmlbeans/impl/common/SoftCache.java store/org/apache/xmlbeans/impl/store/Path.java

Author: cezar
Date: Tue Apr 26 15:19:39 2005
New Revision: 164901

URL: http://svn.apache.org/viewcvs?rev=164901&view=rev
Log:
Use SoftReferences for xquery cache.

Added:
    xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/SoftCache.java
Modified:
    xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Path.java

Added: xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/SoftCache.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/SoftCache.java?rev=164901&view=auto
==============================================================================
--- xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/SoftCache.java (added)
+++ xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/SoftCache.java Tue Apr 26 15:19:39 2005
@@ -0,0 +1,63 @@
+/*   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.xmlbeans.impl.common;
+
+import java.util.HashMap;
+import java.lang.ref.SoftReference;
+
+/**
+ * @author Cezar Andrei (cezar.andrei at bea.com)
+ *         Date: Apr 26, 2005
+ */
+public class SoftCache
+{
+    private HashMap map = new HashMap();
+
+    public Object get(Object key)
+    {
+        SoftReference softRef = (SoftReference)map.get(key);
+
+        if (softRef==null)
+            return null;
+
+        return softRef.get();
+    }
+
+    public Object put(Object key, Object value)
+    {
+        SoftReference softRef = (SoftReference)map.put(key, new SoftReference(value));
+
+        if (softRef==null)
+            return null;
+
+        Object oldValue = softRef.get();
+        softRef.clear();
+
+        return oldValue;
+    }
+
+    public Object remove(Object key)
+    {
+        SoftReference softRef = (SoftReference)map.remove(key);
+
+        if (softRef==null)
+            return null;
+
+        Object oldValue = softRef.get();
+        softRef.clear();
+
+        return oldValue;
+    }
+}
\ No newline at end of file

Modified: xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Path.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Path.java?rev=164901&r1=164900&r2=164901&view=diff
==============================================================================
--- xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Path.java (original)
+++ xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Path.java Tue Apr 26 15:19:39 2005
@@ -21,6 +21,7 @@
 import java.lang.reflect.InvocationTargetException;
 import java.math.BigDecimal;
 
+import org.apache.xmlbeans.impl.common.SoftCache;
 import org.apache.xmlbeans.impl.common.XPath;
 import org.apache.xmlbeans.impl.common.XPath.XPathCompileException;
 import org.apache.xmlbeans.impl.common.XPath.ExecutionContext;
@@ -490,8 +491,8 @@
 
     protected final String _pathKey;
 
-    private static HashMap _xbeanPathCache = new HashMap();
-    private static HashMap _xqrlPathCache = new HashMap();
+    private static SoftCache _xbeanPathCache = new SoftCache();
+    private static SoftCache _xqrlPathCache = new SoftCache();
 
     private static Method _xqrlCompilePath;
 }



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