mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-11 05:13: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:
@@ -332,11 +332,30 @@ class BaseSoccerManager:
|
||||
return set(self.target_leagues_config)
|
||||
|
||||
def _fetch_data(self, date_str: str = None) -> Optional[Dict]:
|
||||
"""Fetch data using shared data mechanism or live fetching per league."""
|
||||
"""
|
||||
Fetch data using background service cache first, fallback to direct API call.
|
||||
This eliminates redundant caching and ensures Recent/Upcoming managers
|
||||
use the same data source as the background service.
|
||||
"""
|
||||
# For Live managers, always fetch fresh data
|
||||
if isinstance(self, SoccerLiveManager) and not self.test_mode:
|
||||
return self._fetch_soccer_api_data(use_cache=False)
|
||||
else:
|
||||
return self._fetch_soccer_api_data(use_cache=True)
|
||||
|
||||
# For Recent/Upcoming managers, try to use background service cache first
|
||||
from datetime import datetime
|
||||
import pytz
|
||||
cache_key = f"soccer_{datetime.now(pytz.utc).strftime('%Y%m%d')}"
|
||||
|
||||
# Check if background service has fresh data
|
||||
if self.cache_manager.is_background_data_available(cache_key, 'soccer'):
|
||||
cached_data = self.cache_manager.get_background_cached_data(cache_key, 'soccer')
|
||||
if cached_data:
|
||||
self.logger.info(f"[Soccer] Using background service cache for {cache_key}")
|
||||
return cached_data
|
||||
|
||||
# Fallback to direct API call if background data not available
|
||||
self.logger.info(f"[Soccer] Background data not available, fetching directly for {cache_key}")
|
||||
return self._fetch_soccer_api_data(use_cache=True)
|
||||
|
||||
def _load_fonts(self):
|
||||
"""Load fonts used by the scoreboard."""
|
||||
|
||||
Reference in New Issue
Block a user