This commit is contained in:
1 parent
2dbe457836
commit
d860157540
10 files changed
+91
-11
No files matched your search
@@ -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 = []
|
||||
|
||||
Reference in new issue
Block a user