Commit 7e2f8bfe authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

* calling has_key() and get() wastes time because they do almost same things.

* implement expiration check in get().


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29663 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b14a568f
...@@ -89,10 +89,10 @@ class CacheFactory: ...@@ -89,10 +89,10 @@ class CacheFactory:
## Expired Cache (if needed) ## Expired Cache (if needed)
self.expire() self.expire()
if self.quick_cache.has_key(cache_id, scope): try:
quick_cached = self.quick_cache.get(cache_id, scope) quick_cached = self.quick_cache.get(cache_id, scope)
return quick_cached.getValue() return quick_cached.getValue()
else: except KeyError:
## not in local, check if it's in shared ## not in local, check if it's in shared
for shared_cache in self.shared_caches: for shared_cache in self.shared_caches:
if shared_cache.has_key(cache_id, scope): if shared_cache.has_key(cache_id, scope):
......
...@@ -74,13 +74,18 @@ class RamCache(BaseCache): ...@@ -74,13 +74,18 @@ class RamCache(BaseCache):
def get(self, cache_id, scope, default=_MARKER): def get(self, cache_id, scope, default=_MARKER):
cache = self.getCacheStorage() cache = self.getCacheStorage()
cache_entry = cache.get((scope, cache_id), default) cache_entry = cache.get((scope, cache_id), default)
if cache_entry is _MARKER:
raise KeyError, 'CacheEntry for key %s not Found' % ((scope, cache_id),)
if isinstance(cache_entry, CacheEntry): if isinstance(cache_entry, CacheEntry):
if not cache_entry.isExpired():
#The value is well retrieved from cache storage #The value is well retrieved from cache storage
cache_entry.markCacheHit() cache_entry.markCacheHit()
self.markCacheHit() self.markCacheHit()
return cache_entry 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),)
return default
def set(self, cache_id, scope, value, cache_duration=None, calculation_time=0): def set(self, cache_id, scope, value, cache_duration=None, calculation_time=0):
cache = self.getCacheStorage() cache = self.getCacheStorage()
......
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