Skip to content

feat(cache): add invalidateCache() and .invalidate() - #8

Merged
pi0 merged 1 commit into
mainfrom
feat/invalidate-cache
Mar 19, 2026
Merged

pi0 merged 1 commit into
mainfrom
feat/invalidate-cache

Conversation

@pi0

@pi0 pi0 commented Mar 19, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds invalidateCache({ options, args }) standalone helper to remove cached entries across all base prefixes
  • Adds .invalidate(...args) method on CachedFunction (same ergonomics as .resolveKeys())
  • Both resolve keys via existing resolveCacheKeys and delete via storage.set(key, null)

Addresses upstream Nitro issues:

Usage

// Via method on cached function
const getUser = defineCachedFunction(fetchUser, {
  name: "getUser",
  getKey: (id: string) => id,
});
await getUser.invalidate("user-123");

// Via standalone helper (when you don't have the function reference)
await invalidateCache({
  options: { name: "getUser", getKey: (id: string) => id },
  args: ["user-123"],
});

Test plan

  • Invalidate removes entry so next call re-invokes the function
  • Invalidate with specific args only affects that key
  • Multi-tier base: invalidates across all prefixes
  • Standalone invalidateCache works with same options
  • Invalidating non-existent key is a no-op
  • All 84 tests pass, typecheck clean

…he invalidation

Adds first-class cache invalidation API — both a standalone `invalidateCache()` helper
and an `.invalidate(...args)` method on cached functions. Resolves keys via existing
`resolveCacheKeys` and deletes entries across all base prefixes via `storage.set(key, null)`.
@coderabbitai

coderabbitai Bot commented Mar 19, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@pi0 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 11 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 17a35e29-aea8-4997-a4c8-47d8142ed3f9

📥 Commits

Reviewing files that changed from the base of the PR and between 1ebe1f6 and 741f849.

📒 Files selected for processing (6)
  • AGENTS.md
  • PLAN.md
  • README.md
  • src/cache.ts
  • src/index.ts
  • test/index.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/invalidate-cache
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant