mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
Fix duplicate caching (#62)
* Fix duplicate/redundant caching issue - Add get_background_cached_data() and is_background_data_available() methods to CacheManager - Update sports managers to use background service cache instead of individual caching - Ensure consistent cache key generation between background service and managers - Eliminate redundant API calls by making Recent/Upcoming managers cache consumers - Fix cache miss issues where TTL < update interval This addresses GitHub issue #57 by implementing a cleaner caching architecture where the background service is the primary data source and managers are cache consumers. * Update remaining sports managers to use background service cache - Update NHL managers to use background service cache - Update NCAA Football managers to use background service cache - Update NCAA Hockey managers to use background service cache - Update MLB managers to use background service cache for Recent/Upcoming All sports managers now use the new caching architecture to eliminate duplicate caching and redundant API calls. * cache improvements * updated cache manager
This commit is contained in:
@@ -410,7 +410,10 @@ class BaseMLBManager:
|
||||
return "TBD"
|
||||
|
||||
def _fetch_mlb_api_data(self, use_cache: bool = True) -> Dict[str, Any]:
|
||||
"""Fetch MLB game data from the ESPN API."""
|
||||
"""
|
||||
Fetch MLB game data from the ESPN API.
|
||||
Updated to use background service cache for Recent/Upcoming managers.
|
||||
"""
|
||||
# Define cache key based on dates
|
||||
now = datetime.now(timezone.utc)
|
||||
yesterday = now - timedelta(days=1)
|
||||
@@ -420,6 +423,16 @@ class BaseMLBManager:
|
||||
|
||||
# If using cache, try to load from cache first
|
||||
if use_cache:
|
||||
# For Recent/Upcoming managers, try background service cache first
|
||||
if hasattr(self, '__class__') and any(x in self.__class__.__name__ for x in ['Recent', 'Upcoming']):
|
||||
if self.cache_manager.is_background_data_available(cache_key, 'mlb'):
|
||||
cached_data = self.cache_manager.get_background_cached_data(cache_key, 'mlb')
|
||||
if cached_data:
|
||||
self.logger.info(f"[MLB] Using background service cache for {cache_key}")
|
||||
return cached_data
|
||||
self.logger.info(f"[MLB] Background data not available, fetching directly for {cache_key}")
|
||||
|
||||
# Fallback to regular cache strategy
|
||||
cached_data = self.cache_manager.get_with_auto_strategy(cache_key)
|
||||
if cached_data:
|
||||
self.logger.info("Using cached MLB API data.")
|
||||
|
||||
Reference in New Issue
Block a user