feat: schedule cover cache maintenance
CI / test (push) Successful in 5m25s

This commit is contained in:
strsv committed 2026-11-06 21:44:48 +03:00
1 parent 2dbe457836
commit d860157540
10 files changed
+91 -11

No files matched your search

+21
View File
@@ -1,6 +1,7 @@
"""Cover cache helpers: optional WebP previews and size pruning."""
import os
import time
try:
from PIL import Image
@@ -51,6 +52,26 @@ def cache_stats(cache_dir):
return {"files": files, "previews": previews, "bytes": total}
def cleanup_negative_markers(cache_dir, ttl):
"""Remove expired .missing markers; returns the number removed."""
removed = 0
if not os.path.isdir(cache_dir):
return removed
now = time.time()
for dirpath, _dirs, names in os.walk(cache_dir):
if ".missing" not in names:
continue
path = os.path.join(dirpath, ".missing")
try:
if now - os.path.getmtime(path) <= ttl:
continue
os.remove(path)
removed += 1
except OSError:
continue
return removed
def prune_cache(cache_dir, max_bytes):
"""Delete oldest cached files until the directory is under max_bytes."""
entries = []