Write JSON before updating cache, removes redundant loading
This commit is contained in:
parent
14971857c7
commit
83d878a6b6
|
@ -74,14 +74,14 @@ def commit(document, data, cache=True):
|
|||
logger.debug("JsonDB: mkdir {}".format(segment))
|
||||
os.mkdir(segment, 0o755)
|
||||
|
||||
# Write the JSON.
|
||||
write_json(path, data)
|
||||
|
||||
# Update the cached document.
|
||||
if cache:
|
||||
set_cache(document, data, expires=cache_lifetime)
|
||||
set_cache(document+"_mtime", time.time(), expires=cache_lifetime)
|
||||
|
||||
# Write the JSON.
|
||||
write_json(path, data)
|
||||
|
||||
# Release the lock.
|
||||
unlock_cache(document)
|
||||
|
||||
|
@ -257,9 +257,11 @@ def lock_cache(key, timeout=5, expire=20):
|
|||
|
||||
# Take the lock.
|
||||
set_cache(lock_key, time.time(), expire)
|
||||
logger.debug("Cache lock acquired: {}, expires in {}s".format(key, expire))
|
||||
return True
|
||||
|
||||
|
||||
def unlock_cache(key):
|
||||
"""Release the lock on a cache key."""
|
||||
del_cache(key + "_lock")
|
||||
logger.debug("Cache lock released: {}".format(key))
|
||||
|
|
Loading…
Reference in New Issue
Block a user