sandbox1
parent
515b573a74
commit
197ad95959
|
@ -20,15 +20,20 @@ def shelf(filename, ttl=0):
|
||||||
filename = os.path.join(CACHE_DIR, filename)
|
filename = os.path.join(CACHE_DIR, filename)
|
||||||
with LOCKS.get(filename, threading.RLock()):
|
with LOCKS.get(filename, threading.RLock()):
|
||||||
# with closing(shelve.open(filename, writeback=True)) as d:
|
# with closing(shelve.open(filename, writeback=True)) as d:
|
||||||
import time
|
d = shelve.open(filename, writeback=True)
|
||||||
if not dict(d):
|
try:
|
||||||
d.update({
|
import time
|
||||||
"created_at": time.time(),
|
if not dict(d):
|
||||||
"data": {},
|
d.update({
|
||||||
})
|
"created_at": time.time(),
|
||||||
elif ttl > 0 and (time.time() - d["created_at"]) > ttl:
|
"data": {},
|
||||||
d["data"] = {}
|
})
|
||||||
return d
|
elif ttl > 0 and (time.time() - d["created_at"]) > ttl:
|
||||||
|
d["data"] = {}
|
||||||
|
return d
|
||||||
|
except:
|
||||||
|
d.close()
|
||||||
|
raise
|
||||||
|
|
||||||
_config = {}
|
_config = {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue