fix: restore clear_cache and get_cache_stats methods in DatabentoHistoricalPriceSource

- Add back clear_cache method that was accidentally removed
- Add file_count and total_size_bytes to get_cache_stats return value
- Update tests for fixed March 2026 default dates
This commit is contained in:
Bu5hm4nn
2026-04-04 23:24:53 +02:00
parent 063ccb6781
commit 5ffe5dd04e
2 changed files with 48 additions and 15 deletions

View File

@@ -318,9 +318,12 @@ class DatabentoHistoricalPriceSource:
"""Get cache statistics."""
cache_dir = self.config.cache_dir
if not cache_dir.exists():
return {"status": "empty", "entries": []}
return {"status": "empty", "entries": [], "file_count": 0, "total_size_bytes": 0}
entries = []
total_size = 0
file_count = 0
for meta_file in cache_dir.glob("*_meta.json"):
try:
with open(meta_file) as f:
@@ -336,7 +339,39 @@ class DatabentoHistoricalPriceSource:
"cost_usd": meta.get("cost_usd"),
}
)
total_size += meta_file.stat().st_size
file_count += 1
except Exception:
continue
return {"status": "populated" if entries else "empty", "entries": entries}
# Count parquet files too
for parquet_file in cache_dir.glob("dbn_*.parquet"):
total_size += parquet_file.stat().st_size
file_count += 1
return {
"status": "populated" if entries else "empty",
"entries": entries,
"file_count": file_count,
"total_size_bytes": total_size,
}
def clear_cache(self) -> int:
"""Clear all cache files.
Returns:
Number of files deleted.
"""
cache_dir = self.config.cache_dir
if not cache_dir.exists():
return 0
count = 0
for cache_file in cache_dir.glob("dbn_*.parquet"):
cache_file.unlink()
count += 1
for meta_file in cache_dir.glob("dbn_*_meta.json"):
meta_file.unlink()
count += 1
return count