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 = {}
def get(self, key):
if key in self._added:
if self._added[key] < time.time():
now = time.time()
for key, value in self._added.items():
if value < now:
del self._added[key]
del self[key]
return
return dict.__getitem__(self, key)
return dict.get(self, key)
def set(self, key, value, ttl=None):
ttl = ttl or self._ttl