Description
get_market is on the hot read path and re-deserializes the full struct. Add an in-instance cache keyed by market_id, invalidated whenever MarketStateManager mutates the market.
Requirements and Context
- Add
MarketReadCache in markets.rs backed by env.storage().instance()
- Invalidate on every write path through
MarketStateManager
- Document TTL behavior
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested Execution
- Fork the repo and create a branch
git checkout -b feat/get-market-hot-path-cache
- Implement changes
contracts/predictify-hybrid/src/markets.rs
contracts/predictify-hybrid/src/storage.rs
- Test and commit
cargo test -p predictify-hybrid markets -- --nocapture
- Cover edge cases: cache miss, cache hit, cache invalidation
- Include test output and notes in the PR
Example commit message
feat: hot-path cache for get_market with explicit invalidation
Acceptance Criteria
Guidelines
- Avoid stale reads at all costs
- Minimum 95% coverage
- Clear documentation and inline comments
- Timeframe: 96 hours
Description
get_marketis on the hot read path and re-deserializes the full struct. Add an in-instance cache keyed by market_id, invalidated wheneverMarketStateManagermutates the market.Requirements and Context
MarketReadCacheinmarkets.rsbacked byenv.storage().instance()MarketStateManagerSuggested Execution
contracts/predictify-hybrid/src/markets.rscontracts/predictify-hybrid/src/storage.rscargo test -p predictify-hybrid markets -- --nocaptureExample commit message
Acceptance Criteria
unwrap()introducedGuidelines