-
-
Notifications
You must be signed in to change notification settings - Fork 18
cache_management
The LEDMatrix application uses caching to improve performance and reduce API calls. However, sometimes cache data can become stale or corrupted, leading to issues like false live game detection or outdated information.
The clear_cache.py script provides a command-line interface for managing the LEDMatrix cache. This utility is essential for debugging cache-related issues and ensuring fresh data retrieval.
# Show help and current cache status
python clear_cache.py
# List all available cache keys
python clear_cache.py --list
# Clear all cache data
python clear_cache.py --clear-all
# Clear a specific cache key
python clear_cache.py --clear KEY_NAME
# Show information about a specific cache key
python clear_cache.py --info KEY_NAME| Command | Short | Description |
|---|---|---|
--list |
-l |
List all available cache keys |
--clear-all |
-a |
Clear all cache data |
--clear KEY |
-c |
Clear a specific cache key |
--info KEY |
-i |
Show information about a specific cache key |
-
milb_live_api_data- Live game data from MiLB API -
milb_upcoming_api_data- Upcoming game schedules -
milb_recent_api_data- Recent game results
-
mlb_live_api_data- Live game data from MLB API -
mlb_upcoming_api_data- Upcoming game schedules -
mlb_recent_api_data- Recent game results
-
soccer_live_api_data- Live soccer match data -
soccer_upcoming_api_data- Upcoming soccer matches
-
weather_api_data- Weather information -
news_api_data- News headlines -
stocks_api_data- Stock market data
Problem: The MiLB manager is showing "Tam vs Dun" as a live game when it's actually old data.
Solution:
# First, check what's in the MiLB live cache
python clear_cache.py --info milb_live_api_data
# Clear the problematic cache
python clear_cache.py --clear milb_live_api_data
# Restart the application to fetch fresh dataProblem: The display is showing outdated game schedules.
Solution:
# Clear all MiLB cache data
python clear_cache.py --clear milb_upcoming_api_data
python clear_cache.py --clear milb_live_api_data
python clear_cache.py --clear milb_recent_api_dataProblem: Multiple cache-related issues or corrupted data.
Solution:
# Nuclear option - clear everything
python clear_cache.py --clear-all
# Verify cache is empty
python clear_cache.py --listProblem: Unusual behavior that might be cache-related.
Solution:
# List all cache keys to see what's stored
python clear_cache.py --list
# Inspect specific cache entries
python clear_cache.py --info milb_live_api_data
python clear_cache.py --info weather_api_data
# Clear specific problematic caches
python clear_cache.py --clear milb_live_api_dataIf you encounter errors about cache directories:
# Check if cache directory exists
ls -la ~/.ledmatrix_cache/
# If it doesn't exist, the application will create it automatically
# You can also manually create it:
mkdir -p ~/.ledmatrix_cache/If you get permission errors:
# Check cache directory permissions
ls -la ~/.ledmatrix_cache/
# Fix permissions if needed
chmod 755 ~/.ledmatrix_cache/
chown $USER:$USER ~/.ledmatrix_cache/If you get import errors when running the script:
# Make sure you're in the LEDMatrix root directory
cd /path/to/LEDMatrix
# Check that the src directory exists
ls -la src/
# Run the script from the correct location
python clear_cache.py --list- After configuration changes - Clear relevant caches when you modify team preferences or display settings
- When experiencing false live data - Clear live game caches if old games appear as "live"
- After API changes - Clear caches if you notice API endpoints have changed
- For debugging - Clear caches when investigating display or data issues
- After long periods of inactivity - Clear caches if the application hasn't been used for days
| Cache Type | Impact of Clearing | When to Clear |
|---|---|---|
| Live game data | Forces fresh live data fetch | False live game detection |
| Upcoming games | Refreshes schedules | Outdated game times |
| Recent games | Updates final scores | Missing recent results |
| Weather | Gets current conditions | Stale weather data |
| News | Fetches latest headlines | Old news stories |
- Targeted Clearing: Clear specific cache keys rather than all cache when possible
-
Verify Results: Use
--infoto check cache contents before and after clearing - Restart Application: Restart the LEDMatrix application after clearing caches
- Monitor Logs: Check application logs after cache clearing to ensure fresh data is fetched
- Backup Important Data: Cache data is automatically regenerated, but be aware that clearing will force new API calls
The cache clearing utility works independently of the main application. You can run it while the application is running, but for best results:
- Stop the LEDMatrix application
- Clear relevant caches
- Restart the application
This ensures the application starts with fresh data and doesn't immediately re-cache potentially problematic data.
You can integrate cache clearing into scripts or cron jobs:
#!/bin/bash
# Daily cache cleanup script
# Clear old live game data at midnight
python clear_cache.py --clear milb_live_api_data
python clear_cache.py --clear mlb_live_api_data
# Log the cleanup
echo "$(date): Cache cleared" >> /var/log/ledmatrix_cache.log#!/bin/bash
# Only clear cache if it's older than 24 hours
# Check cache age and clear if needed
# (This would require additional logic to check cache timestamps)