case0 / src /case_zero /visuals /cache.py
HusseinEid's picture
Case Zero - initial public release (fully local: Qwen2.5-1.5B via llama.cpp + Supertonic, custom pixel-noir SPA via gradio.Server)
414dc55
raw
history blame
628 Bytes
"""Tiny on-disk PNG cache keyed by content hash (path-independent, auto-named)."""
from __future__ import annotations
import hashlib
from collections.abc import Callable
from pathlib import Path
from PIL import Image
def _key_hash(parts: tuple[str, ...]) -> str:
return hashlib.sha256("|".join(parts).encode("utf-8")).hexdigest()[:16]
def cached_png(cache_dir: Path, parts: tuple[str, ...], render: Callable[[], Image.Image]) -> Path:
cache_dir.mkdir(parents=True, exist_ok=True)
path = cache_dir / f"{_key_hash(parts)}.png"
if not path.exists():
render().save(path, format="PNG")
return path