[F] Fix caching failure

This commit is contained in:
2026-03-10 19:48:46 -04:00
parent 9ddbb45327
commit 995d9ff4b5
2 changed files with 30 additions and 1 deletions
+29
View File
@@ -0,0 +1,29 @@
import json
from pathlib import Path
def clean_cache():
cache_dir = Path(__file__).parent / 'data' / 'imdbapi_info'
if not cache_dir.exists():
print(f"Cache directory not found: {cache_dir}")
return
count = 0
for file_p in cache_dir.glob("*.json"):
try:
data = json.loads(file_p.read_text(encoding="utf-8"))
if data.get("code") == "1":
print(f"Removing invalid cache: {file_p.name}")
file_p.unlink()
# Also remove the corresponding args/kwargs text file
txt_p = file_p.with_suffix('.txt')
if txt_p.exists():
txt_p.unlink()
count += 1
except Exception as e:
print(f"Error processing {file_p.name}: {e}")
print(f"Done. Removed {count} 'code=1' cache files.")
if __name__ == "__main__":
clean_cache()
+1 -1
View File
@@ -3,7 +3,7 @@ import urllib.request
import urllib.parse import urllib.parse
from utils import with_disk_cache from utils import with_disk_cache
@with_disk_cache('imdbapi_info') @with_disk_cache('imdbapi_info', should_cache=lambda res: res.get("code") == "0")
def get_imdb_info(imdb_id: str) -> dict: def get_imdb_info(imdb_id: str) -> dict:
""" """
Fetch IMDb info from imdbapi.dev as a fallback or replacement for M-Team. Fetch IMDb info from imdbapi.dev as a fallback or replacement for M-Team.