feat(aggregation): Add persistent cache storage and LRU management

This commit is contained in:
2026-05-04 05:20:03 -04:00
parent 56c752d070
commit fb2df2a758
2 changed files with 64 additions and 2 deletions
+29
View File
@@ -40,7 +40,36 @@ def test_summary_cache():
if cache_dir.exists():
shutil.rmtree(cache_dir)
def test_summary_cache_lru():
cache_dir = Path(".test_cache_lru")
if cache_dir.exists():
shutil.rmtree(cache_dir)
cache_file = cache_dir / "cache.json"
# Create cache with max 2 entries
cache = SummaryCache(str(cache_file), max_entries=2)
cache.set_summary("file1.py", "hash1", "summary1")
cache.set_summary("file2.py", "hash2", "summary2")
cache.set_summary("file3.py", "hash3", "summary3") # This should evict file1.py
assert cache.get_summary("file1.py", "hash1") is None
assert cache.get_summary("file2.py", "hash2") == "summary2"
assert cache.get_summary("file3.py", "hash3") == "summary3"
# Access file2.py, then add file4.py. file3.py should be evicted
cache.get_summary("file2.py", "hash2")
cache.set_summary("file4.py", "hash4", "summary4")
assert cache.get_summary("file3.py", "hash3") is None
assert cache.get_summary("file2.py", "hash2") == "summary2"
assert cache.get_summary("file4.py", "hash4") == "summary4"
if cache_dir.exists():
shutil.rmtree(cache_dir)
if __name__ == "__main__":
test_get_file_hash()
test_summary_cache()
test_summary_cache_lru()
print("Tests passed!")