feat(@cacheable/memory): add hooks like cacheable#1644
Conversation
Add CacheableMemoryHooks enum and hookSync invocations to CacheableMemory for get, getMany, set, setMany, delete, deleteMany, and clear operations. BEFORE hooks allow mutation of parameters (key, value, ttl) before the operation executes, matching the cacheable package's hook pattern. https://claude.ai/code/session_016g93vFCCgE3LPqYRYJWzCG
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1644 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 26 26
Lines 2608 2644 +36
Branches 577 582 +5
=========================================
+ Hits 2608 2644 +36 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive hook system (CacheableMemoryHooks) to CacheableMemory, triggering synchronous hooks before and after major cache operations (get, set, delete, clear). It also adds corresponding unit tests to verify hook behaviors. The reviewer feedback recommends wrapping primitive parameters (like keys and arrays) in mutable objects (e.g., { key } or { keys }) across the hook triggers. This ensures consistency with other hooks and enables listeners to mutate keys (e.g., for prefixing or namespacing) during read and delete operations.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fa651813dc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Code Review FindingsRan a max-effort code review (5 angles + verification + sweep). 6 findings survived verification. Ranked by severity: 1.
|
Summary
CacheableMemoryHooksenum with 14 hooks: BEFORE/AFTER forset,setMany,get,getMany,delete,deleteMany, andclearhookSync()calls into all CacheableMemory operations, matching the hook pattern from thecacheablepackageHook signatures
BEFORE_GETkey: stringAFTER_GET{ key, result }BEFORE_GET_MANYkeys: string[]AFTER_GET_MANY{ keys, result }BEFORE_SET{ key, value, ttl }(mutable)AFTER_SET{ key, value, ttl }BEFORE_SET_MANYitems: CacheableItem[]AFTER_SET_MANYitems: CacheableItem[]BEFORE_DELETEkey: stringAFTER_DELETEkey: stringBEFORE_DELETE_MANYkeys: string[]AFTER_DELETE_MANYkeys: string[]BEFORE_CLEARAFTER_CLEARTest plan
https://claude.ai/code/session_016g93vFCCgE3LPqYRYJWzCG
Generated by Claude Code