Commit 7c588c78 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Lower the overhead of expire.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29675 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d7b173f9
...@@ -76,18 +76,20 @@ class CacheFactory: ...@@ -76,18 +76,20 @@ class CacheFactory:
## set 'check_expire_cache_interval' to the minimal value between ## set 'check_expire_cache_interval' to the minimal value between
## individual 'check_expire_cache_interval' for each cache plugin contained ## individual 'check_expire_cache_interval' for each cache plugin contained
l = [] l = []
self._last_cache_expire_check_at = time()
for cp in self.cache_plugins: for cp in self.cache_plugins:
l.append(cp.cache_expire_check_interval) l.append(cp.cache_expire_check_interval)
l = filter(lambda x: x is not None and x != 0, l) l = filter(lambda x: x is not None and x != 0, l)
self.cache_expire_check_interval = min(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): 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 """ When CacheFactory is called it will try to return cached value using
appropriate cache plugin. appropriate cache plugin.
""" """
## Expired Cache (if needed) ## Expired Cache (if needed)
self.expire() now = time()
if now > self._next_cache_expire_check_at:
self.expire(now)
try: try:
quick_cached = self.quick_cache.get(cache_id, scope) quick_cached = self.quick_cache.get(cache_id, scope)
...@@ -117,13 +119,11 @@ class CacheFactory: ...@@ -117,13 +119,11 @@ class CacheFactory:
shared_cache.set(cache_id, scope, value, cache_duration, calculation_time) shared_cache.set(cache_id, scope, value, cache_duration, calculation_time)
return value return value
def expire(self): def expire(self, now):
""" Expire (if needed) cache plugins """ """ Expire cache plugins """
now = time() self._next_cache_expire_check_at = now + self.cache_expire_check_interval
if now > (self._last_cache_expire_check_at + self.cache_expire_check_interval): for cache_plugin in self.getCachePluginList():
self._last_cache_expire_check_at = now cache_plugin.expireOldCacheEntries()
for cache_plugin in self.getCachePluginList():
cache_plugin.expireOldCacheEntries()
def getCachePluginList(self, omit_cache_plugin_name=None): def getCachePluginList(self, omit_cache_plugin_name=None):
""" get list of all cache plugins except specified by name in omit """ """ get list of all cache plugins except specified by name in omit """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment