Skip to content

feat(cache): add resolveCacheKey and .resolveKey() - #6

Merged
pi0 merged 12 commits into
mainfrom
feat/resolvekey
Mar 19, 2026
Merged

pi0 merged 12 commits into
mainfrom
feat/resolvekey

Conversation

@pi0

@pi0 pi0 commented Mar 19, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add resolveCacheKey({ options, args }) standalone utility to resolve the exact storage key using the same derivation logic as defineCachedFunction
  • Attach .resolveKey(...args) method on cached functions returned by defineCachedFunction for convenient key resolution
  • Add CachedFunction type export

Closes #4

Test plan

  • Tests for resolveCacheKey with custom getKey, default hash, custom base/group/name
  • Test verifying .resolveKey() matches internal key used by defineCachedFunction
  • All 72 tests passing

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Cached functions now expose a .resolveKey() method to programmatically compute cache keys.
    • New resolveCacheKey() utility function enables flexible cache key resolution with custom options.
    • Added CachedFunction type for improved TypeScript support.
  • Documentation

    • Introduced cache invalidation guide with practical examples.
    • Enhanced API documentation with detailed storage utility signatures.

…lidation

Add a `resolveCacheKey({ options, args })` utility and a `.resolveKey()` method
on cached functions to resolve the exact storage key, making cache invalidation
straightforward without guessing internal key formats.

Closes #4

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@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 12 minutes and 28 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: 19c18b8b-b506-4887-b1f4-7f134b8140b7

📥 Commits

Reviewing files that changed from the base of the PR and between f4647f2 and 55b51e0.

📒 Files selected for processing (3)
  • .oxfmtrc.json
  • README.md
  • src/cache.ts
📝 Walkthrough

Walkthrough

The changes introduce a resolveCacheKey utility function that programmatically derives cache storage keys based on cache options and arguments. Cached functions now expose a .resolveKey() method. This enables users to construct proper storage keys for cache invalidation without manual string formatting. Documentation and comprehensive tests accompany the implementation.

Changes

Cohort / File(s) Summary
Type and Export Updates
src/cache.ts, src/index.ts
Added new exported CachedFunction<T, ArgsT> type with resolveKey method. Introduced resolveCacheKey utility function that computes cache keys using getKey or argument hashing. Updated defineCachedFunction to attach .resolveKey method to returned functions. Refactored internal cache key construction into shared _buildCacheKey helper.
Documentation
README.md
Updated API documentation to showcase .resolveKey() method on cached functions. Added "Cache Invalidation" section demonstrating cache key resolution. Documented new resolveCacheKey function signature and updated related export documentation.
Tests
test/index.test.ts
Added comprehensive test suite for resolveCacheKey covering default key hashing, custom getKey functions, and base/group/name path overrides. Included integration assertions verifying resolveCacheKey produces keys matching internal defineCachedFunction behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A key-finding hop through the cache so deep,
No more strings to guess, no more secrets to keep,
Resolve your way clear with a .resolveKey() call,
Invalidate freely, and conquer them all! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main changes: adding a resolveCacheKey utility function and .resolveKey() method to cached functions, which directly addresses the PR objectives.
Linked Issues check ✅ Passed The PR fully implements the requirements from issue #4: provides resolveCacheKey utility to derive exact storage keys, mirrors key derivation logic from defineCachedFunction with custom getKey support, and enables reliable cache invalidation without manual key reconstruction.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the key resolution feature: new types, exports, functions, and comprehensive tests. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/resolvekey
📝 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.

@pi0
pi0 force-pushed the feat/resolvekey branch from dc8f87c to 55b51e0 Compare March 19, 2026 10:45
@pi0
pi0 merged commit ee34dfe into main Mar 19, 2026
4 checks passed
@pi0
pi0 deleted the feat/resolvekey branch March 19, 2026 10:45
@coderabbitai coderabbitai Bot mentioned this pull request Mar 19, 2026
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.

Util to get key

1 participant