From 1e398ccfe7b04bb48299c8a4ab227bea95cfd283 Mon Sep 17 00:00:00 2001 From: Nicolas Delaby <nicolas@nexedi.com> Date: Fri, 10 Jul 2009 11:19:39 +0000 Subject: [PATCH] * Fix mistake in default_value handling: raise KeyError if value is not found for given key and no default value provided. If default value is provided and value not found for given key, return default_value. * Call markCacheHit only if value is retrieved from cache container. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28050 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/CachePlugins/RamCache.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/product/ERP5Type/CachePlugins/RamCache.py b/product/ERP5Type/CachePlugins/RamCache.py index d24b679280..8a5579e781 100644 --- a/product/ERP5Type/CachePlugins/RamCache.py +++ b/product/ERP5Type/CachePlugins/RamCache.py @@ -49,6 +49,7 @@ def calcPythonObjectMemorySize(i): s += calcPythonObjectMemorySize(v) return s +_MARKER = [] class RamCache(BaseCache): """ RAM based cache plugin.""" @@ -58,7 +59,7 @@ class RamCache(BaseCache): _cache_dict = {} cache_expire_check_interval = 300 - + def __init__(self, params={}): BaseCache.__init__(self) @@ -66,15 +67,19 @@ class RamCache(BaseCache): """ Init cache storage """ ## cache storage is a RAM based dictionary pass - + def getCacheStorage(self, **kw): return self._cache_dict - - def get(self, cache_id, scope, default=None): + + def get(self, cache_id, scope, default=_MARKER): cache = self.getCacheStorage() cache_entry = cache.get((scope, cache_id), default) - cache_entry.markCacheHit() - self.markCacheHit() + if cache_entry 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 def set(self, cache_id, scope, value, cache_duration=None, calculation_time=0): -- 2.30.9