[Erp5-report] r29675 - /erp5/trunk/products/ERP5Type/Cache.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Oct 15 14:40:03 CEST 2009


Author: yo
Date: Thu Oct 15 14:40:02 2009
New Revision: 29675

URL: http://svn.erp5.org?rev=29675&view=rev
Log:
Lower the overhead of expire.

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

Modified: erp5/trunk/products/ERP5Type/Cache.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Cache.py?rev=29675&r1=29674&r2=29675&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Cache.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Cache.py [utf8] Thu Oct 15 14:40:02 2009
@@ -76,18 +76,20 @@
     ## set 'check_expire_cache_interval' to the minimal value between
     ## individual 'check_expire_cache_interval' for each cache plugin contained
     l = []
-    self._last_cache_expire_check_at = time()
     for cp in self.cache_plugins:
       l.append(cp.cache_expire_check_interval)
     l = filter(lambda x: x is not None and x != 0, l)
     self.cache_expire_check_interval = min(l)
+    self._next_cache_expire_check_at = time() + self.cache_expire_check_interval
 
   def __call__(self, callable_object, cache_id, scope, cache_duration=None, *args, **kwd):
     """ When CacheFactory is called it will try to return cached value using
     appropriate cache plugin.
     """
     ## Expired Cache (if needed)
-    self.expire()
+    now = time()
+    if now > self._next_cache_expire_check_at:
+      self.expire(now)
 
     try:
       quick_cached = self.quick_cache.get(cache_id, scope)
@@ -117,13 +119,11 @@
       shared_cache.set(cache_id, scope, value, cache_duration, calculation_time)
     return value
 
-  def expire(self):
-    """ Expire (if needed) cache plugins """
-    now = time()
-    if now > (self._last_cache_expire_check_at + self.cache_expire_check_interval):
-      self._last_cache_expire_check_at = now
-      for cache_plugin in self.getCachePluginList():
-        cache_plugin.expireOldCacheEntries()
+  def expire(self, now):
+    """ Expire cache plugins """
+    self._next_cache_expire_check_at = now + self.cache_expire_check_interval
+    for cache_plugin in self.getCachePluginList():
+      cache_plugin.expireOldCacheEntries()
 
   def getCachePluginList(self, omit_cache_plugin_name=None):
     """ get list of all cache plugins except specified by name in omit """




More information about the Erp5-report mailing list