Author: doogie
Date: Wed Oct 17 12:52:19 2007 New Revision: 585647 URL: http://svn.apache.org/viewvc?rev=585647&view=rev Log: Move the hasExpired logic into CacheLine. Closes https://issues.apache.org/jira/browse/OFBIZ-1295 Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/CacheLine.java ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/UtilCache.java Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/CacheLine.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/CacheLine.java?rev=585647&r1=585646&r2=585647&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/CacheLine.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/CacheLine.java Wed Oct 17 12:52:19 2007 @@ -87,5 +87,19 @@ public long getSizeInBytes() { return UtilObject.getByteCount(this); } + + public boolean hasExpired() { + // check this BEFORE checking to see if expireTime <= 0, ie if time expiration is enabled + // check to see if we are using softReference first, slight performance increase + if (softReferenceCleared()) return true; + + // check if expireTime <= 0, ie if time expiration is not enabled + if (expireTime <= 0) return false; + + // check if the time was saved for this; if the time was not saved, but expire time is > 0, then we don't know when it was saved so expire it to be safe + if (loadTime <= 0) return true; + + return (loadTime + expireTime) < System.currentTimeMillis(); + } } Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/UtilCache.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/UtilCache.java?rev=585647&r1=585646&r2=585647&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/UtilCache.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/UtilCache.java Wed Oct 17 12:52:19 2007 @@ -347,7 +347,7 @@ removeInternal(key, false); if (countGet) missCountSoftRef++; line = null; - } else if (this.hasExpired(line)) { + } else if (line.hasExpired()) { // note that print.info in debug.properties cannot be checked through UtilProperties here, it would cause infinite recursion... // if (Debug.infoOn()) Debug.logInfo("Element has expired with key " + key, module); removeInternal(key, false); @@ -599,27 +599,8 @@ */ public boolean hasExpired(Object key) { CacheLine line = getInternalNoCheck(key); - return hasExpired(line); - } - - protected boolean hasExpired(CacheLine line) { if (line == null) return false; - - // check this BEFORE checking to see if expireTime <= 0, ie if time expiration is enabled - // check to see if we are using softReference first, slight performance increase - if (line.softReferenceCleared()) return true; - - // check if expireTime <= 0, ie if time expiration is not enabled - if (line.expireTime <= 0) return false; - - // check if the time was saved for this; if the time was not saved, but expire time is > 0, then we don't know when it was saved so expire it to be safe - if (line.loadTime <= 0) return true; - - if ((line.loadTime + line.expireTime) < System.currentTimeMillis()) { - return true; - } else { - return false; - } + return line.hasExpired(); } /** Clears all expired cache entries; also clear any cache entries where the SoftReference in the CacheLine object has been cleared by the gc */ |
Free forum by Nabble | Edit this page |