sandbox1
parent
971817c888
commit
515b573a74
|
@ -14,12 +14,12 @@ if not os.path.exists(CACHE_DIR):
|
|||
|
||||
CACHE = 24 * 3600 # 24 hour caching
|
||||
|
||||
@contextmanager
|
||||
#@contextmanager
|
||||
def shelf(filename, ttl=0):
|
||||
import shelve
|
||||
filename = os.path.join(CACHE_DIR, filename)
|
||||
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
|
||||
if not dict(d):
|
||||
d.update({
|
||||
|
@ -28,14 +28,16 @@ def shelf(filename, ttl=0):
|
|||
})
|
||||
elif ttl > 0 and (time.time() - d["created_at"]) > ttl:
|
||||
d["data"] = {}
|
||||
yield d["data"]
|
||||
return d
|
||||
|
||||
_config = {}
|
||||
|
||||
def config():
|
||||
global _config
|
||||
if not _config:
|
||||
with shelf("antizapret.pac_config", ttl=CACHE) as pac_config:
|
||||
# with shelf("antizapret.pac_config", ttl=CACHE) as pac_config:
|
||||
d = shelf("antizapret.pac_config", ttl=CACHE)
|
||||
pac_config = d['data']
|
||||
if not pac_config:
|
||||
log("[antizapret]: Fetching Antizapret PAC file on %s" %PAC_URL)
|
||||
try:
|
||||
|
@ -50,7 +52,7 @@ def config():
|
|||
else:
|
||||
pac_config["server"] = None
|
||||
pac_config["domains"] = []
|
||||
log("[antizapret]: +++++++++++ pac_config %s" % (repr(pac_config),))
|
||||
d.close()
|
||||
_config = pac_config
|
||||
return _config
|
||||
|
||||
|
|
Loading…
Reference in New Issue