Skip to content

Commit

Permalink
Merge pull request #15299 from AUTOMATIC1111/diskcache-bett
Browse files Browse the repository at this point in the history
Tweak diskcache limits
  • Loading branch information
AUTOMATIC1111 authored Mar 17, 2024
2 parents f1b090e + df4da02 commit 8ac4a20
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions modules/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def dump_cache():
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():
try:
with open(cache_filename, "r", encoding="utf8") as file:
Expand All @@ -37,7 +45,7 @@ def convert_old_cached_data():
for subsection, keyvalues in data.items():
cache_obj = caches.get(subsection)
if cache_obj is None:
cache_obj = diskcache.Cache(os.path.join(cache_dir, subsection))
cache_obj = make_cache(subsection)
caches[subsection] = cache_obj

for key, value in keyvalues.items():
Expand All @@ -64,7 +72,7 @@ def cache(subsection):

cache_obj = caches.get(subsection)
if not cache_obj:
cache_obj = diskcache.Cache(os.path.join(cache_dir, subsection))
cache_obj = make_cache(subsection)
caches[subsection] = cache_obj

return cache_obj
Expand Down

0 comments on commit 8ac4a20

Please sign in to comment.