better memcache support?

This commit is contained in:
mdipierro
2012-08-15 14:55:55 -05:00
parent def270c298
commit d9ef136111
3 changed files with 39 additions and 28 deletions
+7 -5
View File
@@ -175,6 +175,7 @@ class CacheInRam(CacheAbstract):
"""
dt = time_expire
now = time.time()
self.locker.acquire()
item = self.storage.get(key, None)
@@ -187,14 +188,14 @@ class CacheInRam(CacheAbstract):
if f is None:
return None
if item and (dt is None or item[0] > time.time() - dt):
if item and (dt is None or item[0] > now - dt):
return item[1]
elif item and (item[0] < time.time() - dt) and destroyer:
elif item and (item[0] < now - dt) and destroyer:
destroyer(item[1])
value = f()
self.locker.acquire()
self.storage[key] = (time.time(), value)
self.storage[key] = (now, value)
self.storage[CacheAbstract.cache_stats_name]['misses'] += 1
self.locker.release()
return value
@@ -345,15 +346,16 @@ class CacheOnDisk(CacheAbstract):
if storage:
storage.close()
now = time.time()
if f is None:
return None
if item and (dt is None or item[0] > time.time() - dt):
if item and (dt is None or item[0] > now - dt):
return item[1]
value = f()
storage = self._open_shelf_with_lock()
try:
storage[key] = (time.time(), value)
storage[key] = (now, value)
storage[CacheAbstract.cache_stats_name] = {
'hit_total': storage[CacheAbstract.cache_stats_name]['hit_total'],