Add debug logging to cache lookup

This commit is contained in:
gilesb
2026-01-08 02:11:37 +00:00
parent 3e12596dbf
commit 01f6db0621
3 changed files with 70 additions and 0 deletions

View File

@@ -243,33 +243,46 @@ class L1CacheManager:
def get_by_content_hash(self, content_hash: str) -> Optional[Path]:
"""Get cached file path by content_hash."""
logger.info(f"get_by_content_hash({content_hash[:16]}...) - cache_dir={self.cache_dir}, nodes_dir={self.cache.cache_dir}")
# Check index first (new cache structure)
node_id = self._content_index.get(content_hash)
if node_id:
logger.info(f" Found in content_index: node_id={node_id[:16]}...")
path = self.cache.get(node_id)
if path and path.exists():
logger.info(f" Found via index: {path}")
return path
logger.info(f" Index entry but path not found: {path}")
# For uploads, node_id == content_hash, so try direct lookup
# This works even if cache index hasn't been reloaded
logger.info(f" Trying direct lookup with content_hash as node_id...")
path = self.cache.get(content_hash)
logger.info(f" cache.get({content_hash[:16]}...) returned: {path}")
if path and path.exists():
logger.info(f" Found via direct lookup: {path}")
self._content_index[content_hash] = content_hash
self._save_content_index()
return path
# Scan cache entries (fallback for new structure)
logger.info(f" Trying find_by_content_hash...")
entry = self.cache.find_by_content_hash(content_hash)
if entry and entry.output_path.exists():
logger.info(f" Found via scan: {entry.output_path}")
self._content_index[content_hash] = entry.node_id
self._save_content_index()
return entry.output_path
# Check legacy location (files stored directly as CACHE_DIR/{content_hash})
legacy_path = self.cache_dir / content_hash
logger.info(f" Checking legacy path: {legacy_path}, exists={legacy_path.exists()}")
if legacy_path.exists() and legacy_path.is_file():
logger.info(f" Found at legacy location: {legacy_path}")
return legacy_path
logger.info(f" NOT FOUND anywhere")
return None
def has_content(self, content_hash: str) -> bool: