feat(backend): Redis cache for quote Soroban simulations - #273
Merged
jhayniffy merged 2 commits intoMar 29, 2026
Merged
Conversation
- SHA-256 keys from sorted normalized GeneratePremiumDto + contract + network
- Store only successful source=simulation results; TTL via QUOTE_SIMULATION_CACHE_TTL_SECONDS (default 30s)
- Cache-Control: no-cache bypasses cache; counter quote_simulation_cache_requests_total{result}
- Invalidate quote:sim:v1:* on indexer niffyins:tbl_upd (parseEvent)
- Fix claims.controller missing class brace, indexer duplicate handleClaimFiled
- Fix throttler Redis storage import path and ThrottlerStorageRecord type import
- app.module: import RedisService and RedisThrottlerStorage for ThrottlerModule factory
- Docs: quote-simulation-cache.md; observability metric table
- Tests: cache key util + integration with in-memory TTL Redis mock
Made-with: Cursor
|
@Jambox11 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
Adds a short-TTL Redis cache for successful Soroban
generate_premiumsimulations behindPOST /api/quote/generate-premium, keyed by a SHA-256 of normalized quote inputs plus contract id and network passphrase. Reduces duplicate RPC work for identical quotes within the TTL window.closes #203
What changed
Quote simulation cache
quote:sim:v1:+ SHA-256(CONTRACT_ID+STELLAR_NETWORK_PASSPHRASE+ canonical JSON with sorted fields:age,coverage_tier,policy_type,region,risk_score,source_account).source: "simulation"only — notlocal_fallback, not thrown errors (avoids caching transient failures).env.validation.ts):QUOTE_SIMULATION_CACHE_ENABLED(defaulttrue),QUOTE_SIMULATION_CACHE_TTL_SECONDS(default 30, max 600).Cache-Controlheader containing theno-cachedirective skips Redis read/write.quote_simulation_cache_requests_total{result="hit"|"miss"|"bypass"}.delPatternwhenparseEventreturnsniffyins:tbl_upd(multiplier table update).Files
quote-simulation-cache-key.util.ts,quote-simulation-cache.service.tsquote.service.ts,quote.controller.ts,quote.module.ts(exports cache service for indexer)indexer.service.ts/indexer.module.ts— invalidation hookmetrics.service.ts— new counterdocs/quote-simulation-cache.md,docs/observability.mdTests
quote-simulation-cache-key.util.test.ts— canonical JSON + hash stabilityquote-simulation-cache.integration.test.ts— hit, miss, bypass, TTL expiry, no cache forlocal_fallback(in-memory TTL Redis mock)