[jbosscache-commits] JBoss Cache SVN: r7088 - core/trunk/src/main/java/org/jboss/cache/interceptors.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Nov 5 15:34:07 EST 2008


Author: genman
Date: 2008-11-05 15:34:07 -0500 (Wed, 05 Nov 2008)
New Revision: 7088

Modified:
   core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
Log:
JBCACHE-1439
Fix CacheLoaderInterceptor calls both CacheLoader.exist() and get() for every load

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java	2008-11-05 19:01:32 UTC (rev 7087)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java	2008-11-05 20:34:07 UTC (rev 7088)
@@ -283,10 +283,22 @@
             if (isNew && n != null) n.setDataLoaded(false);
          }
 
+         // This is really convoluted
          if (n == null || !n.isDeleted())
          {
-            if (n == null && loader.exists(fqn))
+            boolean exists;
+            Map nodeData = null;
+            if (bypassLoadingData)
             {
+               exists = loader.exists(fqn);
+            }
+            else
+            {
+               nodeData = loadData(fqn);
+               exists = nodeData != null;
+            }
+            if (n == null && exists)
+            {
                // just create a dummy node in memory
                n = helper.wrapNodeForWriting(ctx, fqn, true, true, true, false, false);
                n.setDataLoaded(false);
@@ -295,9 +307,9 @@
             {
                this.cacheMisses++;   
             }
-            if (!bypassLoadingData && n != null)
+            if (nodeData != null && n != null)
             {
-               n = loadNode(ctx, fqn, n);
+               setNodeState(ctx, fqn, n, nodeData);
             }
          }
       }
@@ -428,14 +440,11 @@
     * If it doesn't exist on disk but in memory, clears the
     * uninitialized flag, otherwise returns null.
     */
-   private NodeSPI loadNode(InvocationContext ctx, Fqn fqn, NodeSPI n) throws Exception
+   private void setNodeState(InvocationContext ctx, Fqn fqn, NodeSPI n, Map nodeData) throws Exception
    {
-      if (trace) log.trace("loadNode " + fqn + " node is " + n);
-      Map nodeData = loadData(fqn);
+      if (trace) log.trace("setNodeState node is " + n);
       if (nodeData != null)
       {
-         if (trace) log.trace("Node data is not null, loading");
-
          notifier.notifyNodeLoaded(fqn, true, Collections.emptyMap(), ctx);
          if (isActivation)
          {
@@ -445,7 +454,7 @@
          n.setInternalState(nodeData);
 
          // set this node as valid?
-//         if (usingVersionedInvalidation) n.setValid(true, false);
+         //         if (usingVersionedInvalidation) n.setValid(true, false);
          n.setValid(true, false);
 
          notifier.notifyNodeLoaded(fqn, false, nodeData, ctx);
@@ -454,12 +463,11 @@
             notifier.notifyNodeActivated(fqn, false, nodeData, ctx);
          }
       }
-      if (n != null && !n.isDataLoaded())
+      if (!n.isDataLoaded())
       {
          if (trace) log.trace("Setting dataLoaded to true");
          n.setDataLoaded(true);
       }
-      return n;
    }
 
    private Map loadData(Fqn fqn) throws Exception
@@ -496,6 +504,7 @@
    }
 
    @ManagedOperation
+   @Override
    public void resetStatistics()
    {
       cacheLoads = 0;
@@ -503,6 +512,7 @@
    }
 
    @ManagedOperation
+   @Override
    public Map<String, Object> dumpStatistics()
    {
       Map<String, Object> retval = new HashMap<String, Object>();




More information about the jbosscache-commits mailing list