Skip to content

sdk: add getRound caching with explicit invalidation - #189

Open
Ugooweb wants to merge 1 commit into
Sub-Rosa-Issue:mainfrom
Ugooweb:feat/sdk-cache-round
Open

sdk: add getRound caching with explicit invalidation#189
Ugooweb wants to merge 1 commit into
Sub-Rosa-Issue:mainfrom
Ugooweb:feat/sdk-cache-round

Conversation

@Ugooweb

@Ugooweb Ugooweb commented Jul 30, 2026

Copy link
Copy Markdown

Closes #158

Summary

Provides an optional short-lived cache for getRound and getConfig reads in SubRosaClient, paired with explicit cache invalidation on write operations (e.g. commit, reveal, settle).

Motivation

Dashboards and keeper watch loops frequently re-read the same round state and configuration repeatedly. Previously, these uncached reads added avoidable RPC load and latency. This PR introduces an opt-in TTL-based cache to reduce overhead for consumers making heavy sequential reads while maintaining consistency guarantees by invalidating immediately upon localized state changes.

Changes

  • cacheTtl configuration option: Added a cacheTtl property (in milliseconds) to SubRosaClientConfig. It defaults to 0 (disabled) to remain backwards compatible and avoid stale reads by default.
  • getRound & getConfig caching: Implemented a lightweight in-memory cache map for getRound results indexed by roundId, and a single cache slot for getConfig.
  • Explicit Invalidation: Added #invalidateRound(roundId) which wipes the cache entry for a specific round. This is now called after any successfully submitted state-changing write operations related to a round, specifically: commit, openReveal, reveal, clear, settle, and void.
  • Testing: Added unit tests in client.test.ts to ensure that caching returns results properly without incrementing underlying contract calls and that cache is appropriately invalidated (and fresh reads are fetched) upon write.
  • Documentation: Updated the SDK README.md to document the tradeoffs of using cacheTtl, ensuring developers are aware of how

@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@Ugooweb 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! 🚀

Learn more about application limits

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.

sdk: add getRound caching with explicit invalidation

1 participant