better cache cleanup
This commit is contained in:
parent
045eb91be3
commit
563c2af2c3
1 changed files with 4 additions and 4 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue