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:
@@ -128,11 +128,22 @@ class BackgroundDataService:
|
||||
|
||||
logger.info(f"BackgroundDataService initialized with {max_workers} workers")
|
||||
|
||||
def get_sport_cache_key(self, sport: str, date_str: str = None) -> str:
|
||||
"""
|
||||
Generate consistent cache keys for sports data.
|
||||
This ensures Recent/Upcoming managers and background service
|
||||
use the same cache keys.
|
||||
"""
|
||||
# Use the centralized cache key generation from CacheManager
|
||||
from src.cache_manager import CacheManager
|
||||
cache_manager = CacheManager()
|
||||
return cache_manager.generate_sport_cache_key(sport, date_str)
|
||||
|
||||
def submit_fetch_request(self,
|
||||
sport: str,
|
||||
year: int,
|
||||
url: str,
|
||||
cache_key: str,
|
||||
cache_key: str = None,
|
||||
params: Optional[Dict[str, Any]] = None,
|
||||
headers: Optional[Dict[str, str]] = None,
|
||||
timeout: Optional[int] = None,
|
||||
@@ -160,6 +171,10 @@ class BackgroundDataService:
|
||||
if self._shutdown:
|
||||
raise RuntimeError("BackgroundDataService is shutting down")
|
||||
|
||||
# Generate cache key if not provided
|
||||
if cache_key is None:
|
||||
cache_key = self.get_sport_cache_key(sport)
|
||||
|
||||
request_id = f"{sport}_{year}_{int(time.time() * 1000)}"
|
||||
|
||||
# Check cache first
|
||||
|
||||
Reference in New Issue
Block a user