diff --git a/src/mlb_manager.py b/src/mlb_manager.py index 5e6f44a9..8c3256ee 100644 --- a/src/mlb_manager.py +++ b/src/mlb_manager.py @@ -159,6 +159,14 @@ class BaseMLBManager: # ESPN API endpoint for MLB games url = "https://site.api.espn.com/apis/site/v2/sports/baseball/mlb/scoreboard" + # Try to get cached data first + cache_key = f"mlb_games_{datetime.now().strftime('%Y%m%d')}" + cached_data = self.cache_manager.get(cache_key) + + if cached_data: + self.logger.info("Using cached MLB game data") + return cached_data + self.logger.info("Fetching MLB games from ESPN API") response = self.session.get(url, headers=self.headers, timeout=10) response.raise_for_status() @@ -215,6 +223,12 @@ class BaseMLBManager: 'start_time': event['date'] } + # Cache the results with different expiration times based on game status + cache_duration = 300 # 5 minutes for live games + if not any(game['status'] == 'in' for game in games.values()): + cache_duration = 3600 # 1 hour for non-live games + + self.cache_manager.set(cache_key, games, cache_duration) return games except Exception as e: