Repository navigation
client cache: opt-in / opt-out by mode and by flag (CacheOptIn, CacheOptOut, TrackingOptIn, TrackingByPrefix) - #3297
Merged
Merged
Conversation
…OptIn/CacheOptOut (two bits, both-set reserved) replace NoClientCache; Tracking negotiates OPTOUT, new TrackingOptIn negotiates OPTIN, new TrackingByPrefix (OPTIN, Prefixes applied client-side, flags win) is what Prefixes now select by default; CLIENT CACHING YES|NO travels as a per-request prefix frame written as one unit with the request (RESPite IRespMessage.Prefix + discard sink); a transaction that reads is sent behind CACHING NO under OPTOUT
…ases (the second zero-valued name, PreferMaster, is appended to every non-zero value on .NET Framework)
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.
Client-side caching gains a real opt-in / opt-out story, on both halves: what the cache keeps locally, and what the server is told to track.
Per-command flags
CommandFlags.NoClientCache(unshipped) is replaced by a two-bit field:CacheOptOut(bit 20): not served from or stored in the cache; underTrackingthe server is also told not to track the key.CacheOptIn(bit 21): stored on first miss, skipping admission; under the OPTIN modes it is what makes a read cacheable at all, and the server is told to track it.ArgumentExceptionat the send funnel, cache or no cache.Bit 19 was shared with the internal probe flag; the move resolves that. The command surface's "never cached" marker (random members, TTLs) is now a separate internal bit with no wire effect, so a
CLIENT CACHING NOis not paid perHPTTL.Tracking modes
Tracking(default)ON OPTOUTONon Redis 8.9, except that it permitsCACHING NOTrackingByPrefix(default whenPrefixesset)ON OPTINPrefixes: asCacheOptIn; outside: plainPrefixesstay client-side (PREFIXneedsBCAST); the flags override the listTrackingOptInON OPTINBroadcastON BCAST [PREFIX ...]PrefixesDefaultwithPrefixesnow resolves toTrackingByPrefixrather thanBroadcast, for the same reasonDefaultmoved off broadcast earlier: broadcast's cost is set by the server's write rate, the new mode's by this client's own misses. Broadcast remains available by name. Consequence: with prefixes set, a read inside them is cached on its first miss rather than its second.How
CLIENT CACHINGgets on the wireA request can carry a prefix: one complete frame that the connection writes immediately before the request, under the same write lock, enqueueing a per-connection discard sink for its reply (
IRespMessage.Prefix,RespPrefixReplySink). Adjacency therefore holds by construction under every write path: single sends, pairs behindSELECT/ASKING/SCRIPT LOAD, batch runs, and the inbox drain. An error reply to a prefix is swallowed and counted (RespConnection.PrefixErrors,LastPrefixError), so a refused modifier degrades a read to uncached rather than failing it. The prefix is not part of the cache key.Where frames go:
YESahead of the read that fills (and a refresh) under the OPTIN modes;NOahead of aCacheOptOutread underTracking, and ahead of a transaction'sMULTIwhen the transaction contains a read, since reads insideMULTIare never cached. Never ahead of a write, never insideMULTI, never underBroadcast.A RESP3 push arriving between the prefix's
+OKand the body's reply consumes nothing: pushes are classified before any dequeue. Covered by a RESPite test with the raw frame order and an in-proc test that forces the interleave through a new toy-server hook.High-integrity mode:
ConfigurationOptions.HighIntegrityis not consumed by the v4 core yet, so there is nothing to interact with; if it is later built as a trailing per-command frame, the same stage-and-sink mechanism serves it.Toy server
Models
OPTIN/OPTOUT,CLIENT CACHING YES|NOwith the real server's error strings, the "next command consumes it,MULTIcarries it" rule, and exposes per-client counters,IsTrackingKey, and anAfterReplyhook.Tests
RESPite 1960 passed (6 new). Main suite net10.0: 7773 passed, 166 skipped. New coverage: every cell of the mode-by-flag table, admission bypass, the reserved encoding, the transaction prefix, a renamed
CLIENT, prefix-not-in-key, OPTOUT/OPTIN negotiation, the OPTIN and by-prefix flows end to end with invalidation, the flag overrides underTrackingByPrefix, the transaction opt-out, and the forced push interleave.Docs
docs/ClientSideCaching.md(modes, flag table, admission, intro example),design/client-side-cache.md§6/§7, flag rename indocs/Extending.mdanddesign/command-flow.md.