better cache cleanup

This commit is contained in:
j 2016-02-15 19:43:40 +05:30
parent 045eb91be3
commit 563c2af2c3

View file

@ -7,12 +7,12 @@ class Cache(dict):
self._added = {} self._added = {}
def get(self, key): def get(self, key):
if key in self._added: now = time.time()
if self._added[key] < time.time(): for key, value in self._added.items():
if value < now:
del self._added[key] del self._added[key]
del self[key] del self[key]
return return dict.get(self, key)
return dict.__getitem__(self, key)
def set(self, key, value, ttl=None): def set(self, key, value, ttl=None):
ttl = ttl or self._ttl ttl = ttl or self._ttl