aboutsummaryrefslogtreecommitdiffstats
path: root/modules/cache.py
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2023-08-22 14:45:38 +0000
committerAUTOMATIC1111 <16777216c@gmail.com>2023-08-22 14:45:47 +0000
commitbb7dd7b64668d4b645dba38a3bc52be452d14eb8 (patch)
tree0fb3b4bbfb83e37b1afd9703fd6327b982f4abd1 /modules/cache.py
parent9c82b34be71a791e33c44f1290fcadadfe0d9ac4 (diff)
downloadstable-diffusion-webui-gfx803-bb7dd7b64668d4b645dba38a3bc52be452d14eb8.tar.gz
stable-diffusion-webui-gfx803-bb7dd7b64668d4b645dba38a3bc52be452d14eb8.tar.bz2
stable-diffusion-webui-gfx803-bb7dd7b64668d4b645dba38a3bc52be452d14eb8.zip
use an atomic operation to replace the cache with the new version
Diffstat (limited to 'modules/cache.py')
-rw-r--r--modules/cache.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/modules/cache.py b/modules/cache.py
index a7cd3aeb..ff26a213 100644
--- a/modules/cache.py
+++ b/modules/cache.py
@@ -30,9 +30,12 @@ def dump_cache():
time.sleep(1)
with cache_lock:
- with open(cache_filename, "w", encoding="utf8") as file:
+ cache_filename_tmp = cache_filename + "-"
+ with open(cache_filename_tmp, "w", encoding="utf8") as file:
json.dump(cache_data, file, indent=4)
+ os.replace(cache_filename_tmp, cache_filename)
+
dump_cache_after = None
dump_cache_thread = None