Skip to content

feat(snap-networks-utils): move cache utils into shared lib - #287

Open
taran-a wants to merge 2 commits into
mainfrom
feat/move-cache-into-shared-lib
Open

feat(snap-networks-utils): move cache utils into shared lib#287
taran-a wants to merge 2 commits into
mainfrom
feat/move-cache-into-shared-lib

Conversation

@taran-a

@taran-a taran-a commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Explanation

Extracts the duplicated caching layer shared by the Solana, Tron, and Stellar snaps into @metamask/snap-networks-utils.

New utils/cache/ module in @metamask/snap-networks-utils, exported from the root entry point:

  • ICache, CacheEntry, TimestampMilliseconds — generic cache contract (identical across all three snaps)
  • InMemoryCache — TTL-backed in-memory cache
  • StateCache — cache backed by a snap state manager, typed against a new minimal structural CacheStateManager interface (getKey/setKey/update) so each snap's existing IStateManager satisfies it without modification
  • useCache / useCacheUntil — function-wrapping helpers with fixed-TTL and dynamic-expiry caching, including stellar's refreshCache option, serialize()-based default key generation, and tron's fix that consults the cache when the in-memory expiry map is empty (so still-valid entries survive a snap restart)

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@taran-a
taran-a requested a review from a team as a code owner September 8, 2026 07:56
@taran-a
taran-a deployed to default-branch September 8, 2026 07:56 — with GitHub Actions Active
@taran-a
taran-a force-pushed the feat/move-cache-into-shared-lib branch from 06c72b4 to f6b8ea4 Compare September 8, 2026 10:30
@taran-a
taran-a force-pushed the feat/move-cache-into-shared-lib branch from f6b8ea4 to b20b6d3 Compare September 8, 2026 10:36
@taran-a taran-a changed the title feat: move cache utils into shared lib feat(snap-networks-utils): move cache utils into shared lib Sep 8, 2026
@taran-a
taran-a force-pushed the feat/move-cache-into-shared-lib branch from b20b6d3 to 2d786db Compare September 9, 2026 08:12
@sonarqubecloud

sonarqubecloud Bot commented Sep 9, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
17.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant