Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak diskcache limits #15299

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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