diff --git a/tradingagents/dataflows/cache_manager.py b/tradingagents/dataflows/cache_manager.py index a871daf0..72e4c5eb 100644 --- a/tradingagents/dataflows/cache_manager.py +++ b/tradingagents/dataflows/cache_manager.py @@ -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 diff --git a/tradingagents/dataflows/data_cache/metadata/AAPL_stock_data_68892ce7b2c5_meta.json b/tradingagents/dataflows/data_cache/metadata/AAPL_stock_data_68892ce7b2c5_meta.json new file mode 100644 index 00000000..1085ae70 --- /dev/null +++ b/tradingagents/dataflows/data_cache/metadata/AAPL_stock_data_68892ce7b2c5_meta.json @@ -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" +} \ No newline at end of file diff --git a/tradingagents/dataflows/data_cache/us_stocks/AAPL_stock_data_68892ce7b2c5.json b/tradingagents/dataflows/data_cache/us_stocks/AAPL_stock_data_68892ce7b2c5.json new file mode 100644 index 00000000..dedad8d6 --- /dev/null +++ b/tradingagents/dataflows/data_cache/us_stocks/AAPL_stock_data_68892ce7b2c5.json @@ -0,0 +1,3 @@ +{ + "data": "Test stock data for AAPL" +} \ No newline at end of file