feat: Clean cache periodically if thread is not available

This commit is contained in:
Kumi 2025-04-14 13:22:30 +02:00
parent 53fa3e3fe2
commit 7e3e88cb74
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -9,6 +9,7 @@ import hashlib
import time
import threading
import shutil
import random
logger = logging.getLogger(__name__)
@ -215,6 +216,13 @@ def init_proxy_routes(app):
logger.debug(f"Proxy request for URL: {url}, filename: {filename}")
# Check if the cache cleanup thread is running
if cache_cleanup_thread is None:
# Use every 100th request to trigger cleanup
if random.randint(1, 100) == 1:
logger.debug("Triggering cache cleanup")
cache_cleanup(app)
if url is not None:
if url.startswith("https://cdn.instructables.com/") or url.startswith(
"https://content.instructables.com/"