Merge pull request #15299 from AUTOMATIC1111/diskcache-bett

Tweak diskcache limits
This commit is contained in:
AUTOMATIC1111 2024-03-17 23:59:12 +03:00 committed by GitHub
commit 8ac4a207f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,6 +20,14 @@ def dump_cache():
pass pass
def make_cache(subsection: str) -> diskcache.Cache:
return diskcache.Cache(
os.path.join(cache_dir, subsection),
size_limit=2**32, # 4 GB, culling oldest first
disk_min_file_size=2**18, # keep up to 256KB in Sqlite
)
def convert_old_cached_data(): def convert_old_cached_data():
try: try:
with open(cache_filename, "r", encoding="utf8") as file: with open(cache_filename, "r", encoding="utf8") as file:
@ -37,7 +45,7 @@ def convert_old_cached_data():
for subsection, keyvalues in data.items(): for subsection, keyvalues in data.items():
cache_obj = caches.get(subsection) cache_obj = caches.get(subsection)
if cache_obj is None: if cache_obj is None:
cache_obj = diskcache.Cache(os.path.join(cache_dir, subsection)) cache_obj = make_cache(subsection)
caches[subsection] = cache_obj caches[subsection] = cache_obj
for key, value in keyvalues.items(): for key, value in keyvalues.items():
@ -64,7 +72,7 @@ def cache(subsection):
cache_obj = caches.get(subsection) cache_obj = caches.get(subsection)
if not cache_obj: if not cache_obj:
cache_obj = diskcache.Cache(os.path.join(cache_dir, subsection)) cache_obj = make_cache(subsection)
caches[subsection] = cache_obj caches[subsection] = cache_obj
return cache_obj return cache_obj