Skip to content

Add manual cache invalidation API to watchAndInvalidate #423

Description

@Lakes41

Difficulty: Intermediate
Type: Feature
Recommended labels (if available in this repo): enhancement, caching, sdk

Background

src/contracts/watchAndInvalidate.ts appears to handle automatic cache invalidation based on on-chain events. There is currently no way for a consumer to manually force-invalidate a cache entry (e.g. after performing a mutation through another path, like an admin action in guildpass-integrations).

Problem

If a consumer application changes on-chain or off-chain state through a path the SDK isn't watching (e.g. a direct admin API call), the SDK's cache can serve stale data until the next automatic invalidation trigger fires.

Expected Outcome

A public client.cache.invalidate(key | pattern) method that lets consumers manually evict specific cache entries or entries matching a pattern (e.g. by wallet address or guild ID).

Suggested Implementation

Expose an invalidate method on the client that delegates to the configured cache adapter's delete/clear methods, and extend watchAndInvalidate.ts to support a pattern-based invalidation helper if the underlying cache doesn't natively support pattern matching (e.g. by tracking key prefixes).

Acceptance Criteria

  • client.cache.invalidate() is implemented and exported
  • Supports invalidating a single known key and a prefix/pattern
  • Works correctly regardless of which cache adapter (in-memory, Redis, LRU) is configured
  • Unit tests cover single-key and pattern invalidation
  • pnpm test:run passes

Likely Affected Files/Directories

  • src/contracts/watchAndInvalidate.ts
  • src/cache/cache.types.ts
  • src/client/GuildPassClient.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSGrantFox Open Source Sponsorship program tagMaybe RewardedIssue may qualify for a reward upon successful completion per campaign rulesOfficial Campaign | FWC26Official FWC26 campaign issue — eligible for campaign scoring and rewards

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions