feat(client): add OPTIN/OPTOUT tracking modes to client-side caching - #3473
Merged
Merged
Conversation
Add a `trackingMode` option ("plain" | "optin" | "optout") and a
`cacheable(command, keys)` predicate to the client-side cache config,
and a per-call `cache` command option. Intent resolves as: the per-call
mark, then the predicate, then the mode default. Eligibility still wins.
`CLIENT CACHING YES|NO` is sent as a queue prelude of the read, so the
pair is admitted, cancelled, encoded, written, and failed as one unit.
When the flag fails, the reply is returned but not cached.
`handleCache` keeps its callback contract; tracking confirmation is an
optional trailing `isStorable` parameter, so existing custom providers
are unaffected.
PavelPashov
marked this pull request as ready for review
September 26, 2026 11:52
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 066479e. Configure here.
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.

Description
Adds opt-in and opt-out tracking modes to client-side caching. Nothing changes with the defaults.
trackingMode:"plain"(default),"optin"or"optout". Also exported asCLIENT_SIDE_CACHE_TRACKING_MODES.cacheable(command, keys): decides caching for reads without a per-callcacheoption.cache: true | falsecommand option, which overridescacheable, which overrides the mode default. Ineligible commands are never cached.strict(experimental):cache: trueon an ineligible command rejects withClientSideCacheMarkErrorbefore it's sent.CLIENT CACHING YES|NOtravels as the read's prelude. It's sent again afterMOVED, and skipped on ASK.CLIENT CACHING/CLIENT TRACKINGcalls reject withClientSideCacheCommandError.Discussion
commandsQueueMaxLength, but two once written. Up to 2× the limit can reach the wire. Should we count them properly, or document it?cache: trueis ignored in this case with no warning or strict error. Should client-side caching support custom type mappings, or should we document the limit and warn?Checklist
npm testpass with this change (including linting)?Note
Medium Risk
Changes command execution, queue admission, and cache storage semantics for RESP3 client-side caching; defaults are unchanged but OPTIN/OPTOUT and prelude pairing bugs could cause stale or untracked entries.
Overview
Adds OPTIN/OPTOUT client-side caching so apps can control what Redis tracks and what gets stored locally, without changing default
"plain"behavior.New
clientSideCacheoptions includetrackingMode(plain/optin/optout, exported asCLIENT_SIDE_CACHE_TRACKING_MODES), optionalcacheable(command, keys), experimentalstrict, and per-callcache: true | falseviawithCommandOptions. Intent resolves as: command option →cacheable→ mode default. Ineligible commands never cache;cache: trueon them warns or rejects withClientSideCacheMarkErrorwhenstrictis on.The client issues
CLIENT CACHING YES/NOthrough a new command queue prelude so the flag and read are admitted, encoded, and cancelled as one unit (avoiding stray flags when the queue is full).CLIENT TRACKING/CLIENT CACHINGfrom the app are blocked withClientSideCacheCommandError(includingmulti, pipelines, and rawsendCommand). OPTIN paths skip storing replies when the caching flag fails (e.g. ACL).Documentation moves to
docs/client-side-caching.mdwith README and configuration updates; broad integration tests cover standalone, cluster, and queue edge cases.Reviewed by Cursor Bugbot for commit 066479e. Bugbot is set up for automated code reviews on this repo. Configure here.