David Prince
production: clean source snapshot — no history bloat
71b4454
Raw
History Blame Contribute Delete
708 Bytes
import hashlib
from typing import Dict, Set
class IncrementalIndexerCache:
"""Tracks file content hashes to prevent redundant AST parsing."""
def __init__(self):
self._hashes: Dict[str, str] = {}
def _compute_hash(self, content: str) -> str:
return hashlib.sha256(content.encode('utf-8')).hexdigest()
def should_reindex(self, filepath: str, content: str) -> bool:
content_hash = self._compute_hash(content)
if self._hashes.get(filepath) == content_hash:
return False
self._hashes[filepath] = content_hash
return True
def invalidate(self, filepath: str):
self._hashes.pop(filepath, None)