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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user