portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glenn Golden <ggol...@umich.edu>
Subject Patch EXAMPLE for some changes to the db psml
Date Mon, 08 Jul 2002 01:36:57 GMT
Here's the patch for a *prior version* (1.15) of
DatabasePsmlManagerService.java - just to give you an idea of what I did.
It changes the WeakHashMap to a HashMap, and caches misses as well as hits.
It's nice that HashMaps can hold nulls as values; you have to use
.containsKey() instead of just get() to test if it's in there (get() returns
null if it's there and null, or if it's not there).

When I have time, if nobody beats me to it, I'll apply the changes to the
tip version and check it in.

- Glenn

--------------------------------------------
Glenn R. Golden, Systems Research Programmer 
University of Michigan School of Information
ggolden@umich.edu               734-615-1419
--------------------------------------------





Index: DatabasePsmlManagerService.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager
/db/DatabasePsmlManagerService.java,v
retrieving revision 1.15
diff -u -r1.15 DatabasePsmlManagerService.java
---
src/java/org/apache/jetspeed/services/psmlmanager/db/DatabasePsmlManagerServ
ice.java	6 Apr 2002 23:41:46 -0000	1.15
+++
src/java/org/apache/jetspeed/services/psmlmanager/db/DatabasePsmlManagerServ
ice.java	30 Jun 2002 01:46:02 -0000
@@ -116,7 +116,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.Vector;
-import java.util.WeakHashMap;
+import java.util.HashMap;
 import java.io.IOException;
 import java.io.FileReader;
 import java.io.File;
@@ -138,7 +138,7 @@
                                      implements PsmlManagerService,
DBOperations
 {
 
-    private Map psmlCache = new WeakHashMap();
+    private Map psmlCache = new HashMap();
 
     /** The watcher for the document locations */
     private CacheRefresher refresher = null;
@@ -324,13 +324,9 @@
                             {
                                 String locator = (String)i.next();
  
-                                // do refresh for the locator
+                                // do refresh for the locator - refresh
will cache what it finds
                                 PSMLDocument doc = 
 
refresh(stringToLocator(locator)); 
-
-                                // over write the existing document in
cache
-                Log.info("Putting profile in cache, Locator string: " +
locator);
-                                psmlCache.put(locator, doc);
                             }
                         }
                     }
@@ -507,14 +503,20 @@
         }
 
         PSMLDocument psmldoc = null;
+        String locStr = locatorToString(locator);
+        boolean inCache = false;
 
         synchronized (psmlCache)
         {
-            Log.info("Getting profile from cache, Locator string: " +
locatorToString(locator));
-            psmldoc =
(PSMLDocument)psmlCache.get(locatorToString(locator));
+            // if we have seached and found nothing, this is cached as a
null value
+            // so check to see if the key is there
+            inCache = psmlCache.containsKey(locStr);
+            if (inCache) psmldoc = (PSMLDocument)psmlCache.get(locStr);
         }
+        Log.info("DatabasePsmlManagerService.getDocument(): psmlcache: " +
(inCache ? ((psmldoc == null) ? "null present" : "doc present") : "not in
cache") + " : " + locStr);
 
-        if (psmldoc != null)
+        // if in the cache, doc or null, return what's in the cache
+        if (inCache)
         {
             return psmldoc;
         }
@@ -971,7 +973,13 @@
                     psmlCache.put(locatorToString(locator), psmldoc);
                 }
                 return psmldoc;
-            } 
+            }
+            else
+            {
+                // cache the fact that there is NO document matching this
profile
+                psmlCache.put(locatorToString(locator), null);
+                Log.info("Putting null in cache, in refresh method, Locator
string: " + locatorToString(locator));
+            }
         }
         catch (Exception e)
         {
@@ -1091,3 +1099,4 @@
     }
 
 }
+

--
To unsubscribe, e-mail:   <mailto:jetspeed-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@jakarta.apache.org>


Mime
View raw message