Repository navigation
cache-manager - fix: read raw entries with getRaw() for Keyv 6 stores - #1759
Open
yan-almeida wants to merge 7 commits into
Open
yan-almeida wants to merge 7 commits into
yan-almeida wants to merge 7 commits into
Conversation
Add the keyv6 alias (npm:keyv@^6.1.0). The tests use it to make a Keyv 6 store. The runtime dependency stays at keyv ^5.6.0.
Keyv 6 get() does not have the raw option. It returns the value and not the stored entry. Thus wrap() calls the function each time, and ttl() returns undefined. These tests fail before the fix.
ttl() and wrap() read the stored entry with get(key, { raw: true }).
Keyv 6 ignores this option, so these calls got the value and not the
entry. Use getRaw(key). Keyv 5.6.0 and Keyv 6 both have getRaw().
ttl() reads with getRaw() now. A mock on get() does not reach the error path, and the catch blocks of ttl() lose their coverage.
wrap() reads with getRaw() now. A mock on get() does not make the store read fail.
wrap() reads with getRaw() now. A mock on get() does not make the read of the first store fail.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
yan-almeida
marked this pull request as ready for review
November 10, 2026 16:37
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix.
Fixes #1758
Problem
ttl()andwrap()read the stored entry withstore.get(key, { raw: true }). Keyv 6get()does not have therawoption, so it returns the value. With a Keyv 6 store,wrap()calls the function each time, andttl()returnsundefined.Change
packages/cache-manager/src/index.ts:ttl()andwrap()usestore.getRaw(key). Keyv 5.6.0 and Keyv 6 both havegetRaw(). Thekeyvdependency stays at^5.6.0.packages/cache-manager/package.json: add the dev dependency"keyv6": "npm:keyv@^6.1.0". The new tests use it to make a real Keyv 6 store.Behavior with Keyv 5:
wrap()andttl()do not change.get()catches a store error, butgetRaw()does not (see cacheable - fix: count falsy values in delete stats #1743). Both call sites incache-managercatch the error.wrap()goes to the next store or calls the function, as before.ttl()also emits itsttlevent with the error.get()does the same with itsgetevent.preGetRawandpostGetRawhooks for these reads, and notpreGetandpostGet.Verification
pnpm install --frozen-lockfile,pnpm buildandnode scripts/test-build.mjspass.pnpm test:ciinpackages/cache-managerpasses with a local Redis. The Biome check passes, 92 tests pass, and coverage is 100% for statements, branches, functions and lines.pnpm exec tsc --noEmit -p packages/cache-managerpasses.wrap returns the cached value: the function runs 2 times, expected 1.ttl returns the expiration: receivedundefined.@keyv/redis6.1.0 and keyv 6.1.0 callswrap()5 times. On 7.2.9 the function runs 5 times, andttl()returnsundefined. On this branch the function runs 1 time, andttl()returns a number. With keyv 5.6.0 and@keyv/redis5.1.6, the result is the same on 7.2.9 and on this branch.Test audit:
Keyv 6 store > wrap returns the cached value.wrap()returns the cached value from a Keyv 6 store and does not call the function again.get(key, { raw: true }). Keyv 6 returns the value, sowrap()finds no entry.get()acceptsraw.createCache()with a real Keyv 6 instance.Keyv 6 store > ttl returns the expiration.ttl()returns the expiration of a key in a Keyv 6 store.ttl()gets the value, and the value has noexpires.gettogetRawinttl.test.ts(error,error on non-blocking enabled),wrap.test.ts(store get failed) andmultiple-stores.test.ts(wrap,wrap - refresh).ttl()andwrap()read withgetRaw()now, so a mock ongetdoes not reach the error path. Without this change,store get failedandmultiple stores > wrapfail, and lines 194 and 206 ofindex.tslose coverage. The tests keep their contract: a store read error does not stopttl()orwrap().