Skip to content

Conversation

@mb43
Copy link
Owner

@mb43 mb43 commented Dec 14, 2025

Problem:

  • Fetching every second caused 429 rate limit errors from CoinGecko
  • Free tier API has strict rate limits

Solution - Smart Caching System:

  • Add api_cache dict with configurable TTL per data source:

    • Price data: 60 second cache (low volatility)
    • Network stats: 5 second cache (more dynamic)
    • Block reward: 30 second cache (rarely changes)
  • Cache logic:

    1. Check if cache is valid (within TTL)
    2. Return cached value if valid (mark as "cached")
    3. If expired, fetch fresh data from API
    4. On API failure, fall back to expired cache
    5. Update status indicator accordingly

Features:

  • is_cache_valid(): Check cache age vs TTL
  • get_cached_value(): Retrieve from cache
  • set_cache(): Store with timestamp
  • Graceful degradation on API failures
  • Visual feedback (orange=cached, green=live, red=failed)

Cache TTLs:

  • Prices: 60s (avoid rate limits)
  • Network: 5s (near real-time)
  • Block reward: 30s (slow changing)

This allows 1-second UI updates while respecting API limits.

Problem:
- Fetching every second caused 429 rate limit errors from CoinGecko
- Free tier API has strict rate limits

Solution - Smart Caching System:
- Add api_cache dict with configurable TTL per data source:
  * Price data: 60 second cache (low volatility)
  * Network stats: 5 second cache (more dynamic)
  * Block reward: 30 second cache (rarely changes)

- Cache logic:
  1. Check if cache is valid (within TTL)
  2. Return cached value if valid (mark as "cached")
  3. If expired, fetch fresh data from API
  4. On API failure, fall back to expired cache
  5. Update status indicator accordingly

Features:
- is_cache_valid(): Check cache age vs TTL
- get_cached_value(): Retrieve from cache
- set_cache(): Store with timestamp
- Graceful degradation on API failures
- Visual feedback (orange=cached, green=live, red=failed)

Cache TTLs:
- Prices: 60s (avoid rate limits)
- Network: 5s (near real-time)
- Block reward: 30s (slow changing)

This allows 1-second UI updates while respecting API limits.
@mb43 mb43 merged commit 56410d4 into main Dec 14, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants