Fix cache file serving after cache_manager integration

- Update get_cached endpoint to check cache_manager first, then legacy
- Update get_cached_mp4 endpoint similarly
- Make cache_file() create symlink in legacy location for backward compat

Fixes issue where newly cached outputs weren't being served because
they were stored in new location but served from legacy location.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gilesb
2026-01-08 01:08:40 +00:00
parent ea60afb624
commit 26768b5942

View File

@@ -161,8 +161,21 @@ def cache_file(source: Path, node_type: str = "output") -> str:
Copy file to cache using L1CacheManager, return content hash.
Uses artdag's Cache internally for proper tracking.
Also creates a symlink in legacy location for backward compatibility.
"""
cached = cache_manager.put(source, node_type=node_type)
# Create symlink in legacy location for backward compatibility
legacy_path = CACHE_DIR / cached.content_hash
if not legacy_path.exists():
try:
legacy_path.symlink_to(cached.path)
except (OSError, FileExistsError):
# Symlink failed, try copy
import shutil
if not legacy_path.exists():
shutil.copy2(cached.path, legacy_path)
return cached.content_hash
@@ -754,9 +767,16 @@ async def list_runs(request: Request, page: int = 1, limit: int = 20):
@app.get("/cache/{content_hash}")
async def get_cached(content_hash: str):
"""Get cached content by hash."""
cache_path = CACHE_DIR / content_hash
# Try cache_manager first (new location)
cache_path = cache_manager.get_by_content_hash(content_hash)
if not cache_path.exists():
# Fallback to legacy location
if not cache_path:
legacy_path = CACHE_DIR / content_hash
if legacy_path.exists():
cache_path = legacy_path
if not cache_path or not cache_path.exists():
raise HTTPException(404, f"Content {content_hash} not in cache")
return FileResponse(cache_path)
@@ -765,10 +785,18 @@ async def get_cached(content_hash: str):
@app.get("/cache/{content_hash}/mp4")
async def get_cached_mp4(content_hash: str):
"""Get cached content as MP4 (transcodes MKV on first request, caches result)."""
cache_path = CACHE_DIR / content_hash
# Try cache_manager first (new location)
cache_path = cache_manager.get_by_content_hash(content_hash)
# Fallback to legacy location
if not cache_path:
legacy_path = CACHE_DIR / content_hash
if legacy_path.exists():
cache_path = legacy_path
mp4_path = CACHE_DIR / f"{content_hash}.mp4"
if not cache_path.exists():
if not cache_path or not cache_path.exists():
raise HTTPException(404, f"Content {content_hash} not in cache")
# If MP4 already cached, serve it