Author: rmannibucau
Date: Sat Sep  2 17:48:25 2017
New Revision: 1807066

URL: http://svn.apache.org/viewvc?rev=1807066&view=rev
Log:
extract CompositeCache.get logging from the synchronized block and only test 
isDebugEnabled once per method call (logging layers are impacting)

Modified:
    
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java

Modified: 
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java?rev=1807066&r1=1807065&r2=1807066&view=diff
==============================================================================
--- 
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java
 (original)
+++ 
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java
 Sat Sep  2 17:48:25 2017
@@ -504,7 +504,8 @@ public class CompositeCache<K, V>
 
         boolean found = false;
 
-        if ( log.isDebugEnabled() )
+        final boolean debugEnabled = log.isDebugEnabled(); // tested anyway 
but don't test it > once
+        if (debugEnabled)
         {
             log.debug( "get: key = " + key + ", localOnly = " + localOnly );
         }
@@ -521,22 +522,12 @@ public class CompositeCache<K, V>
                     // Found in memory cache
                     if ( isExpired( element ) )
                     {
-                        if ( log.isDebugEnabled() )
-                        {
-                            log.debug( cacheAttr.getCacheName() + " - Memory 
cache hit, but element expired" );
-                        }
-
                         missCountExpired.incrementAndGet();
                         remove( key );
                         element = null;
                     }
                     else
                     {
-                        if ( log.isDebugEnabled() )
-                        {
-                            log.debug( cacheAttr.getCacheName() + " - Memory 
cache hit" );
-                        }
-
                         // Update counters
                         hitCountRam.incrementAndGet();
                     }
@@ -555,7 +546,7 @@ public class CompositeCache<K, V>
 
                             if ( !localOnly || cacheType == 
CacheType.DISK_CACHE )
                             {
-                                if ( log.isDebugEnabled() )
+                                if (debugEnabled)
                                 {
                                     log.debug( "Attempting to get from aux [" 
+ aux.getCacheName() + "] which is of type: "
                                         + cacheType );
@@ -571,7 +562,7 @@ public class CompositeCache<K, V>
                                 }
                             }
 
-                            if ( log.isDebugEnabled() )
+                            if (debugEnabled)
                             {
                                 log.debug( "Got CacheElement: " + element );
                             }
@@ -581,7 +572,7 @@ public class CompositeCache<K, V>
                             {
                                 if ( isExpired( element ) )
                                 {
-                                    if ( log.isDebugEnabled() )
+                                    if (debugEnabled)
                                     {
                                         log.debug( cacheAttr.getCacheName() + 
" - Aux cache[" + aux.getCacheName() + "] hit, but element expired." );
                                     }
@@ -597,7 +588,7 @@ public class CompositeCache<K, V>
                                 }
                                 else
                                 {
-                                    if ( log.isDebugEnabled() )
+                                    if (debugEnabled)
                                     {
                                         log.debug( cacheAttr.getCacheName() + 
" - Aux cache[" + aux.getCacheName() + "] hit" );
                                     }
@@ -625,11 +616,22 @@ public class CompositeCache<K, V>
         {
             missCountNotFound.incrementAndGet();
 
-            if ( log.isDebugEnabled() )
+            if (debugEnabled)
             {
                 log.debug( cacheAttr.getCacheName() + " - Miss" );
             }
         }
+        else if (debugEnabled) // we log here to avoid to log in the 
synchronized block
+        {
+            if (element == null)
+            {
+                log.debug( cacheAttr.getCacheName() + " - Memory cache hit, 
but element expired" );
+            }
+            else
+            {
+                log.debug( cacheAttr.getCacheName() + " - Memory cache hit" );
+            }
+        }
 
         if (element != null)
         {


Reply via email to