feat: Integrate Redis caching for vault rates retrieval and add abstractions for cache management#1254
feat: Integrate Redis caching for vault rates retrieval and add abstractions for cache management#1254halaprix wants to merge 2 commits into
Conversation
…actions for cache management
WalkthroughAdded a 60s timeout to generated functions, introduced Redis-backed optional caching for /vault/rates with deterministic cache keys, added input and env validation, and a noop fallback cache when Redis/config is missing. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Handler
participant Redis as Redis Cache
participant Service as Rates Service
participant DB as Database
Client->>Handler: POST /vault/rates?withCache=true
activate Handler
Handler->>Handler: Validate STAGE, body, fleets
alt cache available & withCache
Handler->>Redis: GET cacheKey
alt hit
Redis-->>Handler: cached response
else miss
Handler->>Service: init rates service
Service->>DB: fetch fleet data
DB-->>Service: fleet info
Service-->>Handler: computed rates
Handler->>Redis: SET cacheKey (TTL)
end
else cache disabled or without withCache
Handler->>Service: init rates service
Service->>DB: fetch fleet data
DB-->>Service: fleet info
Service-->>Handler: computed rates
end
Handler-->>Client: return rates response
deactivate Handler
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro Knowledge base: Disabled due to 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (3)
stacks/apy.ts(1 hunks)summerfi-api/get-vault-rates-function/package.json(1 hunks)summerfi-api/get-vault-rates-function/src/index.ts(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Build and Integration Test
- GitHub Check: Build and Unit Test
🔇 Additional comments (7)
summerfi-api/get-vault-rates-function/package.json (1)
18-19: LGTM!Dependencies align with the new caching implementation.
stacks/apy.ts (1)
38-44: LGTM!60s timeout is reasonable for cache+DB operations.
summerfi-api/get-vault-rates-function/src/index.ts (5)
15-31: LGTM!Deterministic key generation with proper sorting.
134-156: Cache always written, only conditionally read.This warms cache for all requests but only reads when
withCache=true. Intentional?
162-175: LGTM!No caching for historicalRates as per PR plan.
187-190: LGTM!DB cleanup in finally; Redis connection reuse across invocations is appropriate.
45-48: No issues found. The noop cache implementation provides both required methods (getandset) that match theDistributedCacheinterface exactly. The type assertion is appropriate and does not hide any missing methods.
Description
Implemented Redis caching for the
get-vault-rates-functionto improve performance and reduce load on the database for the/vault/ratesendpoint.Changes
@summerfi/redis-cacheand@summerfi/abstractionsdependencies tosummerfi-api/get-vault-rates-function/package.json.summerfi-api/get-vault-rates-function/src/index.tsto include:getCacheInstance).generateCacheKey).withCache=true(or purely based on internal logic if we decide to enforce it).Benefits
get-rates-function.Testing
generateCacheKeyproduces deterministic keys regardless of input order./vault/rateswith a set of fleets.?withCache=true.Next steps
/vault/historicalRatesendpoint if traffic patterns warrant it.Additional Notes
chainIdandfleetAddressto ensuring that requests asking for the same fleets in different orders utilize the same cache entry.@summerfi/get-rates-function.Summary by CodeRabbit
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.