svn commit: r929828 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r929828 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java

doogie-3
Author: doogie
Date: Thu Apr  1 04:40:07 2010
New Revision: 929828

URL: http://svn.apache.org/viewvc?rev=929828&view=rev
Log:
Move the creation of the cache line instances to an internal helper
method.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java?rev=929828&r1=929827&r2=929828&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java Thu Apr  1 04:40:07 2010
@@ -231,20 +231,21 @@ public class UtilCache<K, V> implements
         return put(key, value, expireTime);
     }
 
+    private CacheLine<V> createCacheLine(V value, long expireTime) {
+        if (expireTime > 0) {
+            return useSoftReference ? new SoftRefCacheLine<V>(value, System.currentTimeMillis(), expireTime) : new HardRefCacheLine<V>(value, System.currentTimeMillis(), expireTime);
+        } else {
+            return useSoftReference ? new SoftRefCacheLine<V>(value, 0, expireTime) : new HardRefCacheLine<V>(value, 0, expireTime);
+        }
+    }
+
     /** Puts or loads the passed element into the cache
      * @param key The key for the element, used to reference it in the hastables and LRU linked list
      * @param value The value of the element
      * @param expireTime how long to keep this key in the cache
      */
     public V put(K key, V value, long expireTime) {
-        CacheLine<V> oldCacheLine;
-        CacheLine<V> newCacheLine;
-        if (expireTime > 0) {
-            newCacheLine = useSoftReference ? new SoftRefCacheLine<V>(value, System.currentTimeMillis(), expireTime) : new HardRefCacheLine<V>(value, System.currentTimeMillis(), expireTime);
-        } else {
-            newCacheLine = useSoftReference ? new SoftRefCacheLine<V>(value, 0, expireTime) : new HardRefCacheLine<V>(value, 0, expireTime);
-        }
-        oldCacheLine = cacheLineTable.put(key, newCacheLine);
+        CacheLine<V> oldCacheLine = cacheLineTable.put(key, createCacheLine(value, expireTime));
 
         if (oldCacheLine == null) {
             noteAddition(key, value);