feat: add Redis-backed caching for external API calls#157
Merged
Conversation
Contributor
|
✅ Looks good, @Divineifed1. Clean separation between the cache helper and existing call sites, sensible TTLs (60s balances, 30s prices), and Redis is a nice pick. Merging. |
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
close #58
summary:
Reduces redundant external API calls by caching token prices and Stellar balance queries in Redis.
Changes
quantara/web_app/contract_tools/cache.py (new): shared async Redis cache utility with lazy connection pool and graceful fallback on cache errors.
quantara/web_app/contract_tools/mixins/dashboard.py: DashboardMixin.get_current_prices() now cached at quantara:prices with 30s TTL.
quantara/web_app/contract_tools/blockchain_call.py: StellarClient.get_token_balances() now cached at quantara:balances:{address} with 60s TTL.
Impact
Removes N+1 per-user Horizon calls on each dashboard request.
Eliminates CoinGecko fetch on every dashboard refresh.
Cache is disabled-on-failure: Redis outage falls through to existing API fetch behavior with a warning log.
Notes for reviewers
Uses redis.asyncio from the already-pinned redis==8.0.0 dependency; no new packages.
REDIS_URL env var pattern matches existing usage in the rate limiter and health check.
Mock tests targeting APIRequest/get_token_balances should remain green because configuration runs through the patched names