feat: integrate database cache into CLI startup logic
� Cache Integration Enhancements: - Modify get_cache() to use IntegratedCacheManager by default - Automatic fallback from database cache to file cache - Intelligent cache selection based on configuration � Integration Features: - IntegratedCacheManager now used in CLI startup - Supports both database and file-based caching - Automatic detection of database availability - Graceful degradation when databases unavailable ✅ Test Results: - Cache selection logic: ✅ Pass - Cache functionality: ✅ Pass - Database cache available but disabled by default - File cache working as fallback � User Experience: - Default: File-based cache (fast, no setup required) - Optional: Database cache (enable with MONGODB_ENABLED=true) - Seamless transition between cache types - No breaking changes to existing functionality � Current Status: - Cache Type: IntegratedCacheManager - Adaptive Cache: Disabled (databases disabled in .env) - MongoDB: Disabled by default - Redis: Disabled by default - Fallback: Traditional file cache working perfectly Now users get database cache benefits when enabled, with automatic fallback to reliable file cache.
This commit is contained in:
parent
8acf6feec0
commit
1bbe898812
|
|
@ -435,19 +435,36 @@ class StockDataCache:
|
|||
# Global cache instance
|
||||
_global_cache = None
|
||||
|
||||
def get_cache(cache_dir: str = None) -> StockDataCache:
|
||||
def get_cache(cache_dir: str = None):
|
||||
"""
|
||||
Get global cache instance
|
||||
Get global cache instance with intelligent cache selection
|
||||
|
||||
This function will automatically choose between:
|
||||
1. Integrated cache (with database support) if available
|
||||
2. Traditional file cache as fallback
|
||||
|
||||
Args:
|
||||
cache_dir: Cache directory path
|
||||
|
||||
Returns:
|
||||
StockDataCache instance
|
||||
Cache instance (IntegratedCacheManager or StockDataCache)
|
||||
"""
|
||||
global _global_cache
|
||||
if _global_cache is None:
|
||||
_global_cache = StockDataCache(cache_dir)
|
||||
# Try to use integrated cache manager first
|
||||
try:
|
||||
from .integrated_cache import IntegratedCacheManager
|
||||
_global_cache = IntegratedCacheManager(cache_dir)
|
||||
print("🚀 Using integrated cache manager with database support")
|
||||
except ImportError:
|
||||
# Fallback to traditional cache
|
||||
_global_cache = StockDataCache(cache_dir)
|
||||
print("📁 Using traditional file cache")
|
||||
except Exception as e:
|
||||
# If integrated cache fails, fallback to traditional cache
|
||||
print(f"⚠️ Integrated cache initialization failed: {e}")
|
||||
print("📁 Falling back to traditional file cache")
|
||||
_global_cache = StockDataCache(cache_dir)
|
||||
return _global_cache
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"symbol": "AAPL",
|
||||
"data_type": "string",
|
||||
"start_date": "2024-01-01",
|
||||
"end_date": "2024-01-31",
|
||||
"data_source": "test",
|
||||
"market_type": "us",
|
||||
"cache_time": "2025-07-06T01:51:50.484204",
|
||||
"file_path": "C:\\code\\TradingAgents\\tradingagents\\dataflows\\data_cache\\us_stocks\\AAPL_stock_data_68892ce7b2c5.json",
|
||||
"cache_key": "AAPL_stock_data_68892ce7b2c5"
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"data": "Test stock data for AAPL"
|
||||
}
|
||||
Loading…
Reference in New Issue