[Erp5-report] r29663 - in /erp5/trunk/products/ERP5Type: Cache.py CachePlugins/RamCache.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Oct 15 11:50:15 CEST 2009


Author: kazuhiko
Date: Thu Oct 15 11:50:11 2009
New Revision: 29663

URL: http://svn.erp5.org?rev=29663&view=rev
Log:
* calling has_key() and get() wastes time because they do almost same things.
* implement expiration check in get().

Modified:
    erp5/trunk/products/ERP5Type/Cache.py
    erp5/trunk/products/ERP5Type/CachePlugins/RamCache.py

Modified: erp5/trunk/products/ERP5Type/Cache.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Cache.py?rev=29663&r1=29662&r2=29663&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Cache.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Cache.py [utf8] Thu Oct 15 11:50:11 2009
@@ -89,10 +89,10 @@
     ## Expired Cache (if needed)
     self.expire()
 
-    if self.quick_cache.has_key(cache_id, scope):
+    try:
       quick_cached = self.quick_cache.get(cache_id, scope)
       return quick_cached.getValue()
-    else:
+    except KeyError:
       ## not in local, check if it's in shared
       for shared_cache in self.shared_caches:
         if shared_cache.has_key(cache_id, scope):

Modified: erp5/trunk/products/ERP5Type/CachePlugins/RamCache.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/CachePlugins/RamCache.py?rev=29663&r1=29662&r2=29663&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/CachePlugins/RamCache.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/CachePlugins/RamCache.py [utf8] Thu Oct 15 11:50:11 2009
@@ -74,13 +74,18 @@
   def get(self, cache_id, scope, default=_MARKER):
     cache = self.getCacheStorage()
     cache_entry = cache.get((scope, cache_id), default)
-    if cache_entry is _MARKER:
+    if isinstance(cache_entry, CacheEntry):
+      if not cache_entry.isExpired():
+        #The value is well retrieved from cache storage
+        cache_entry.markCacheHit()
+        self.markCacheHit()
+        return cache_entry
+      else:
+        #Delete expired CacheEntry
+        self.delete(cache_id, scope)
+    if default is _MARKER:
       raise KeyError, 'CacheEntry for key %s not Found' % ((scope, cache_id),)
-    if isinstance(cache_entry, CacheEntry):
-      #The value is well retrieved from cache storage
-      cache_entry.markCacheHit()
-      self.markCacheHit()
-    return cache_entry
+    return default
 
   def set(self, cache_id, scope, value, cache_duration=None, calculation_time=0):
     cache = self.getCacheStorage()




More information about the Erp5-report mailing list