↑↓ to navigate Enter to open "…" all these words ANDOR to combine

Architecture Decision Record

ADR-077: HybridCache as an Opt-In ICacheService Substrate (Amends ADR-026)

Status

Accepted (2026-08-13). Amends ADR-026: Tier 1's substrate gains a third implementation beside MemoryCacheService and DistributedCacheService. It is opt-in through AddCommonHybridCache(...); with no call the default path is byte-identical to today, so the release is non-breaking. Revised 2026-10-01 (single-use records read through an L1-bypassing GetFromSharedStoreAsync, and consumers opt in through a Redis-guarded wrapper; see Revision below). Revised 2026-10-06: the ADR-029 registration counter also reads through GetFromSharedStoreAsync, so the member is no longer single-use-only. Revised 2026-10-07: the login-lockout flag and the soft-deleted-user marker also read through GetFromSharedStoreAsync (seven callers), and the source anchors are refreshed after the v1.233.0 release. Revised 2026-10-21: the HybridCacheService TryGetAsync override (presence probe flags and thrown miss sentinel) is now recorded, and the source anchors are refreshed against current source. Revised 2026-10-26: anchors refreshed after the Common releases since 2026-10-21 shifted ICacheService, HybridCacheService, three caller files and two consumer Program.cs files. Revised 2026-10-28: anchors refreshed after v1.262.0 shifted DependencyInjection.Caching.cs. Revised 2026-11-04 (Common v1.277.0): HybridCacheService is the only shared-store substrate (DistributedCacheService and RedisPrefixScanner are removed, so every DistributedCacheService named in this record is the removed type), prefix invalidation is a generation-token write instead of a SCAN, and HybridCache.RemoveByTagAsync is rejected on evidence; see Revision (2026-11-04). Revised 2026-11-23: GetFromSharedStoreAsync has eleven call sites (passkey challenge, sign-in link, lockout expiry and view-as-ended marker added), cross-service xsvc: keys carry no generation token and the constructor takes a sixth optional cross-service namespace, the soft-deleted-user marker now means "deleted or locked", consumers opt in through AddMmcaServiceHost rather than calling the wrapper themselves, and the "byte-identical" claim above holds only for a memory-only host; see Revision (2026-11-23).

Scope note (2026-08-18). This record is Tier 1 only: the Status and Context sections above scope it to ADR-026's Tier 1 substrate, and the Related entry for ADR-040 leaves the Tier 2 output-cache edge untouched. The cross-service output-cache eviction shipped on 2026-08-18 (OutputCacheEvictionRequested plus a per-tag handler on the MMCA.Common.OutputCache meter) is a Tier 2 change and is recorded in ADR-026's Revision (2026-08-18). It touches neither the hc: keyspace, the L1/L2 split, nor anything else decided here: the hybrid substrate and the output-cache edge remain separate invalidation models.

Revised (2026-08-31). HybridCacheService takes a fifth optional constructor parameter, IOptions<CacheSettings>? cacheSettings, which the opt-in registration supplies: the service reads its default and local-cache durations from the bound Cache section instead of from hardcoded constants. The decision is unchanged (disjoint keyspace, opt-in registration, L1 bypass on the counter path); only the recorded constructor shape and the source anchors are.

Context

ADR-026 settled Tier 1 as one abstraction (ICacheService) over two implementations chosen at startup: in-process memory when no real IDistributedCache is present, Redis otherwise. That swap is still right, but in the deployed shape a scaled-out service pays a network hop and a JSON deserialize for every cache read, including reads of small, hot, rarely changing values that every replica wants. Microsoft.Extensions.Caching.Hybrid shipped a two-level cache (an in-process L1 in front of the distributed L2) that removes exactly that cost.

Adopting it is not a drop-in replacement, because ADR-026 also records a production failure that constrains the design. ICacheService.IncrementAsync is a read-modify-write rather than Redis INCR because of a storage-format mismatch, documented then at the DistributedCacheService implementation (removed in v1.277.0) and today on the interface (MMCA.Common/Source/Core/MMCA.Common.Application/Interfaces/ICacheService.cs:126-132): INCR writes a Redis string while StackExchangeRedisCache stores every entry as a Redis hash, so an INCR-written counter answers WRONGTYPE on the next read and surfaces as a 500 on the endpoint that owns the counter. A second cache implementation writing a different payload shape into the same keys is the same failure with a different author, and a rolling deploy guarantees both writers are live at once.

Two further constraints came out of the code rather than the record: the caching decorators of ADR-014 cache only successful Results, and the ADR-029 login counters read a value other replicas increment. Neither survives a naive port onto HybridCache's get-or-create and local cache.

Decision

Ship HybridCacheService as a third ICacheService implementation, opt-in per host, under a disjoint keyspace.

Two serialization formats never share one keyspace

This is the structural rule the design is built around, and everything else follows from it. The WRONGTYPE failure ADR-026 records is a class of bug, not an incident: whenever two writers with different payload shapes address one key, one of them eventually reads what the other wrote. HybridCacheService therefore writes under {prefix}hc:{key}, disjoint from the keyspace the since-removed DistributedCacheService used, so an old-format and a new-format entry could never cross-read, including during a rolling deploy where both versions served traffic against one Redis. With that type gone the rule still holds against a host's own IDistributedCache use and the hcg: generation keys (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Caching/HybridCacheService.cs:20-23).

The alternative considered was a payload discriminator: one keyspace, with each reader detecting and skipping a foreign shape. It lost because it makes the failure unlikely rather than impossible, and because the detection code is exercised only during the migration window it was written for. A disjoint keyspace needs no detection: a reader that cannot see the other format cannot mis-read it. The cost of the split is that a key belongs to exactly one substrate: entries another ICacheService implementation wrote are invisible here and age out on their own TTL (the 30-second ADR-026 default for decorator entries, longer only where a caller asked for longer, and 24 hours for the idempotency records of ADR-017). A host that changes substrate therefore starts cold, which is a cost rather than a correctness problem. Prefix invalidation follows the same rule: its generation tokens fold only into hc: keys (HybridCacheService.cs:440-448, the suffix at :447-448), so what this substrate writes is exactly what an invalidation stops addressing. The one exception is a cross-service key (one starting xsvc:, MMCA.Common/Source/Core/MMCA.Common.Application/Interfaces/CrossServiceCacheKeys.cs:24-27): it is qualified with the cross-service namespace instead of the host's own and carries no generation token (HybridCacheService.cs:442-445, CrossServiceCacheKeys.cs:20-21). That namespace is Cache:CrossServiceKeyPrefix when set, otherwise the token audience (Jwt:Audience), and otherwise the host's own namespace after all (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Caching/CacheKeyPrefix.cs:116-130, the fallback at :126-128), so it is deployment-wide only when one of the first two is configured. Given that, one service writes it, every service reads it, and a prefix wipe in any one service cannot hide it from the others.

ICacheService gains a default GetOrCreateAsync

ICacheService (MMCA.Common/Source/Core/MMCA.Common.Application/Interfaces/ICacheService.cs, GetAsync at :17, SetAsync at :79, RemoveAsync at :89, RemoveByPrefixAsync at :113) gains GetOrCreateAsync<T>(key, factory, expiration?, cancellationToken) (:173) as a default interface member, following the IncrementAsync precedent at :133 precisely because that precedent proved the shape is non-breaking: no existing implementer, in the framework or in a consumer, has to change. The same interface also carries two further default members, TryGetAsync (:34) and GetFromSharedStoreAsync (:69). The default implementation is a presence check through TryGetAsync (:183), so a cached default(T) counts as a hit, then take the key's stripe (:187) from the CacheKeyLocks holder over a KeyedSemaphoreStripe (:217-221, the stripe field at :220, the QueryCacheKeyLocks pattern), double-check with TryGetAsync (:191), call the factory, set. Every backing store therefore gets the process-local stampede protection the query decorator already has, and HybridCacheService can override the member with its native two-level primitive.

HybridCacheService

A new internal sealed partial class HybridCacheService : ICacheService (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Caching/HybridCacheService.cs:55) implements the interface over HybridCache. It takes its dependencies through a constructor, (HybridCache hybrid, ILogger<HybridCacheService> logger, IConnectionMultiplexer? connectionMultiplexer = null, CacheKeyNamespace? keyNamespace = null, IOptions<CacheSettings>? cacheSettings = null, CacheKeyNamespace? crossServiceNamespace = null) (:151-157), the last four optional because a host without Redis still resolves the service, the multiplexer only carries the prefix-invalidation generation tokens (without it they stay in the process, :142-145), the cross-service namespace falls back to keyNamespace (:165), and a directly constructed instance falls back to new CacheSettings() (:166) for its TTL policy. The registration passes all four explicitly rather than leaving them to the container, the settings and CacheKeyNamespace.CrossServiceFrom(sp) included (DependencyInjection.Caching.cs:198-204), so a registered service reads its durations from the bound Cache section rather than from the defaults. It is partial for the LoggerMessage source generator (:491-495), not because the type is split across hand-written files.

  • GetAsync is a read that never writes. It calls HybridCache.GetOrCreateAsync with HybridCacheEntryFlags.DisableUnderlyingData (a shipped 9.0 GA API), which suppresses the factory and writes nothing on a miss. This is the call that earns the feature: an L2 hit is promoted into the calling replica's L1, so the next read of that key costs no hop. The call is wrapped fail-soft: any fault logs a warning, self-heal-deletes the key, and returns the default.
  • SetAsync maps expiration to both levels, with LocalCacheExpiration set to min(local ceiling, expiration) (:466, in WriteOptions at :458-469), the local ceiling being Cache:LocalCacheDuration (CacheSettings.cs:47) when set and otherwise the 30-second LocalCacheDefault (HybridCacheService.cs:71), read at HybridCacheService.cs:461. A shorter caller TTL applies at both levels; a longer one still leaves the L1 copy bounded at the local ceiling.
  • IncrementAsync bypasses L1 on both legs (DisableLocalCacheRead | DisableLocalCacheWrite), keeping today's L2-only read-modify-write semantics exactly. A counter served from a replica's local cache ignores the other replicas' increments, which on the ADR-029 brute-force path means a lockout that never triggers. ADR-026 accepted an occasional lost increment; it did not accept a counter that reads its own stale copy for up to 30 seconds.
  • TryGetAsync reports presence from whether the factory ran. HybridCache has no presence-reporting read, so the override (:224-249) calls GetOrCreateAsync with a factory that throws a tagged KeyNotFoundException (:232, built at :420-425, caught as "not found" at :239) and a third flag set, PresenceProbeOptions (DisableDistributedCacheWrite, :106-109), used by no other call so a probe is never joined with a real get-or-create on the same key. A hit, L1 or L2 promoted into L1, never runs the factory, so a cached default(T) is still found; faults are fail-soft like GetAsync.
  • GetFromSharedStoreAsync reads from L2 alone. The override (:266-285) uses SharedStoreReadOptions (:92-97), the read-only flag plus DisableLocalCacheRead | DisableLocalCacheWrite, so a record another replica already consumed (or a value another replica changed) is a miss or the shared value here rather than a stale local copy. It has eleven call sites in MMCA.Common/Source. Six single-use records read through it: the OAuth exchange code (MMCA.Common/Source/Presentation/MMCA.Common.API/Controllers/OAuthControllerBase.cs:332), the password-reset token (PasswordResetTokenService.cs:128), the email-confirmation token (EmailConfirmationTokenService.cs:95), the two-factor time step (Auth/TwoFactor/TwoFactorAuthenticator.cs:197), the passkey challenge (MMCA.Common/Source/Core/MMCA.Common.Application/Auth/Passkeys/PasskeyChallenges.cs:74) and the sign-in link token (Auth/SignInLinks/SignInLinkTokenService.cs:104). So does one counter: the ADR-029 per-IP registration limit reads its count through it (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Auth/LoginProtectionService.cs:212), because IncrementAsync writes L2 only and a plain GetAsync would let a replica's L1 copy pin the first count it saw, so the limit would not trip while that copy lived. Cross-replica flags read through it as well, because the replica that reads them may not be the one that cleared or set them: the ADR-029 login-lockout flag and its expiry (LoginProtectionService.cs:82, :88), which a reset clears only from the resetting replica's L1; the view-as-ended marker (MMCA.Common/Source/Presentation/MMCA.Common.API/Middleware/ViewAsGuardMiddleware.cs:186), itself a cross-service key that the grant-store host writes and every other service reads (MMCA.Common/Source/Presentation/MMCA.Common.API/Middleware/ViewAsEndedMarker.cs:35-41); and the soft-deleted-user marker (MMCA.Common/Source/Presentation/MMCA.Common.API/Middleware/SoftDeletedUserMiddleware.cs:95). That marker means "deleted or locked": an erasure, an administrator's lock or a machine-client revocation writes it and an unlock clears it (SoftDeletedUserMiddleware.cs:13-16), and on the Identity host the middleware also writes it when its validator finds the user deleted (:17-18). It is a cross-service key that the Identity service writes and every service reads (MMCA.Common/Source/Core/MMCA.Common.Application/Auth/SoftDeletedUserCache.cs:68-74).
  • RemoveByPrefixAsync replaces one generation token (revised 2026-11-04; the original SCAN through a shared RedisPrefixScanner is removed). Every : boundary of a key other than a cross-service xsvc: key (the empty root, then each prefix ending at :) carries a token, and the tokens in force are folded into the stored key (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Caching/HybridCacheService.cs:440-448, boundaries at CachePrefixGenerations.cs:246), so A:B:C carries the tokens of "", A: and A:B:. A cross-service key carries none (HybridCacheService.cs:442-445), so no prefix invalidation reaches it: it is removed by its exact key. RemoveByPrefixAsync checks the boundary contract (HybridCacheService.cs:335, CachePrefixContract.cs:17-27) and writes one fresh random token under {namespace}hcg:{prefix} (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Caching/CachePrefixGenerations.cs:217-238, the write at :237, the key at :281). Every entry written under the old token stops being addressed and expires on its own TTL; nothing is scanned or deleted, so the cost is one Redis write whatever the size of the keyspace. The invalidating process adopts its token at once, before the write (:234-236); another replica sees it within one local cache duration plus one refresh round trip (:37-42).

The caching decorators keep their own stampede logic

CachingQueryDecorator deliberately does not route through GetOrCreateAsync. It caches only successful Results, and HybridCache.GetOrCreateAsync cannot express "store this outcome but not that one" without also caching failures, which would turn a transient handler failure into a cached one for the entry's lifetime. Switching buys nothing anyway: HybridCache's stampede protection is process-local, exactly like the stripe the decorator holds. The decorators keep their read/execute/write sequence and get the L1 benefit for free, because their reads go through GetAsync.

Registration is one opt-in call

AddCommonHybridCache(Action<HybridCacheOptions>? configure = null) (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/DependencyInjection.Caching.cs:162) calls a bare AddHybridCache() (:164) and sets the defaults through AddOptions<HybridCacheOptions>().Configure<IOptions<CacheSettings>> (:170-184) from the bound Cache section (Expiration from DefaultDuration, LocalCacheExpiration from LocalCacheDuration or the 30-second LocalCacheDefault), running the host's configure hook last (:183), then RemoveAll<ICacheService>() (:188) and an AddSingleton<ICacheService> factory (:189-205), not the two-generic-argument AddSingleton<ICacheService, HybridCacheService> form: the lambda resolves the logger (falling back to NullLogger when none is registered), the optional IConnectionMultiplexer, the CacheKeyNamespace, the IOptions<CacheSettings> and the cross-service namespace (CacheKeyNamespace.CrossServiceFrom(sp), :204) itself and hands them to the constructor, rather than leaving the optional parameters to the container. Remove-then-add makes the call order-independent against AddInfrastructure, whose AddCaching registers its substrate with TryAddSingleton (:79): the opt-in wins either way.

Tags are rejected on evidence

HybridCache.RemoveByTagAsync was first deferred (adopting tags means every cache-writing call site declares its tags, a public-contract sweep across three repos) and is rejected as of 2026-11-04: it does not invalidate across replicas. In Microsoft.Extensions.Caching.Hybrid 10.11.0 a tag invalidation stores a timestamp under __MSFT_HCT__{tag} in L2, but each process reads that timestamp once, the first time it meets the tag, and never refreshes it, so another replica that has already seen the tag keeps accepting the L2 payload after its L1 copy expires (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Caching/CachePrefixGenerations.cs:17-24). The generation token is the replacement. The Redis-tier test HybridCacheCrossInstanceInvalidationTests builds two independent cache instances over one Testcontainers Redis (MMCA.Common/Tests/Core/MMCA.Common.Infrastructure.Redis.Tests/HybridCacheCrossInstanceInvalidationTests.cs:32) and pins the cross-replica property the token provides (:63, :107).

Packaging and adoption

Microsoft.Extensions.Caching.Hybrid is pinned in Directory.Packages.props and referenced by MMCA.Common.Infrastructure, with lock files regenerated across the solution and the out-of-slnx Redis tests project (ADR-038). Consumers opt in through the guarded wrapper AddCommonHybridCacheWhenRedisConfigured(configuration) (DependencyInjection.Caching.cs:226-238), which calls AddCommonHybridCache only when the connection string named by connectionName (default redis, :228) is set (:232). No consumer calls it directly: AddMmcaServiceHost calls AddRedisCaching and then the wrapper on every service host (MMCA.Common/Source/Hosting/MMCA.Common.ServiceHost/ServiceHostBuilderExtensions.cs:89, :95), so ADC's four service hosts (for example MMCA.ADC/Source/Services/MMCA.ADC.Conference.Service/Program.cs:82) and Store's three (for example MMCA.Store/Source/Services/MMCA.Store.Catalog.Service/Program.cs:32) opt in through that one call. MMCA.Helpdesk uses neither the service host nor the wrapper (no Redis, so it stays on the memory substrate). Since v1.277.0 the call is required of any host with a distributed cache: without it ICacheService fails to resolve, naming the call (DependencyInjection.Caching.cs:86-92).

Rationale

  • The disjoint keyspace is the decision; everything else is implementation. Rather than trusting a second implementation to write a shape compatible with the first, this record removes the possibility of the two shapes meeting. A cache key belongs to exactly one writer's format.
  • A default interface member is the only non-breaking way to widen this interface. IncrementAsync proved it: implementers inherit working behavior, and the one with something better overrides it.
  • DisableUnderlyingData makes GetAsync honest. Without it, mapping GetAsync onto a get-or-create API would need a factory that fabricates a value, or would write on a read. The flag turns get-or-create into a pure read while keeping the L1 promotion that is the point of adopting HybridCache.
  • The counter path is excluded rather than tuned. A short LocalCacheExpiration would have made the counters "mostly right", the wrong property for the control that decides whether an account is locked. Bypassing L1 on both legs keeps ADR-029's semantics identical to what shipped, and a counter that is read outside IncrementAsync (the registration limit) reads through GetFromSharedStoreAsync for the same reason.
  • Fail-soft matches the existing substrate's posture. ADR-026 already treats prefix invalidation as best-effort with a TTL backstop; a faulting read returning a miss is the same trade.
  • Opt-in keeps the release non-breaking and the monolith cheap. A host with no Redis gains nothing from a two-level cache over an in-process one, so automatic adoption would add a dependency and a second cache layer to hosts that cannot benefit.
  • A generation token makes invalidation constant-cost and convergent. The removed SCAN walked every Redis primary on each invalidation, and a caching command invalidates twice (immediately and once more after a delay). A token write costs the same whatever the keyspace, and a random token rather than an INCR counter needs no atomicity: whichever concurrent write lands last wins and both invalidated (CachePrefixGenerations.cs:27-29).

Trade-offs

  • Invalidation does not reach other replicas' L1 immediately. A remove evicts the L2 entry and the calling replica's L1; every other replica keeps its copy for up to LocalCacheExpiration (30 seconds). The command decorator's delayed 5-second re-invalidation already tolerates a comparable race, but this is a second and longer staleness window that did not exist before. A prefix invalidation is bounded the same way: another replica adopts the new token within one local duration plus one refresh round trip (CachePrefixGenerations.cs:37-42).
  • Single-use records stay out of that window only when read through GetFromSharedStoreAsync. The framework's own single-use reads (OAuth exchange code, password reset, email confirmation, two-factor time step, passkey challenge, sign-in link) bypass L1, so their replay exposure is bounded by the record's removal; the registration-limit counter read, the login-lockout flag and its expiry, the view-as-ended marker and the soft-deleted-user marker take the same path. A caller that reads a replay-guard value through plain GetAsync can still be served a stale local copy for up to LocalCacheExpiration.
  • AddCommonHybridCache overwrites a host's own ICacheService. RemoveAll<ICacheService>() is what makes the call order-independent, and it is also indiscriminate: a host that registered a custom implementation loses it silently. Deliberate, and a sharp edge for anyone who had one.
  • A key belongs to exactly one substrate, so changing substrate costs a cold cache. Entries another ICacheService implementation wrote are invisible here, and neither a read nor a prefix eviction reaches them: they age out on their own TTL, and until they do Redis holds both keyspaces at once.
  • Fail-soft turns a broken cache into database load, quietly. A warning log per fault is the only signal; the endpoint keeps answering while the database absorbs the traffic the cache used to.
  • The counter path gets none of the benefit. IncrementAsync opting out of L1 leaves ADR-029's hot path exactly as expensive as before: correct, and an uneven benefit across the interface.
  • A wider public contract, even when non-breaking. GetOrCreateAsync is a member three repos now inherit, and it caches unconditionally (failures included, unlike the decorators), so a caller who assumes decorator semantics can misuse it.
  • Generation tokens trade the SCAN for orphans and a baseline window. Invalidated entries are not deleted: they occupy Redis until their own TTL. A generation key carries no TTL, so if one is lost (eviction, or a failover or restart without persistence) its prefix reads as the empty baseline again and the entries written before that prefix's first invalidation are addressed until their TTL (CachePrefixGenerations.cs:27-34); keep generation keys out of eviction where that matters. During a partial Redis outage (L2 reads succeed, token reads fail) a cold replica can address a prefix's pre-invalidation entries until their TTL, the cost of the baseline fallback that keeps the lockout flag, counters and idempotency records in the shared keyspace (:52-61).

Revision (2026-10-01)

Two decisions joined the record. First, ICacheService gained GetFromSharedStoreAsync (MMCA.Common/Source/Core/MMCA.Common.Application/Interfaces/ICacheService.cs:62), which HybridCacheService overrides (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Caching/HybridCacheService.cs:150-169) with SharedStoreReadOptions (:82-87), bypassing L1 on both legs exactly as the counter path does, and the framework's single-use records read through it (OAuthControllerBase.cs:196, PasswordResetTokenService.cs:128, EmailConfirmationTokenService.cs:90, TwoFactorAuthenticator.cs:105). The former trade-off that OAuth state and nonce records inherit the L1 staleness window no longer describes the code; no ICacheService-held OAuth state or nonce record exists in Common (the UI's per-attempt OAuth flow state sits in the device-local ILocalCacheStore, MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/OAuth/OAuthFlowStateStore.cs:20, which has no L1 window). Second, consumers opt in through AddCommonHybridCacheWhenRedisConfigured (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/DependencyInjection.Caching.cs:200-212), so a host without the redis connection string keeps its existing substrate. Also corrected: the default GetOrCreateAsync checks presence through TryGetAsync (ICacheService.cs:155, :163), the L1 ceiling is Cache:LocalCacheDuration with a 30-second fallback (HybridCacheService.cs:319) rather than CacheOptions.DefaultDuration, and AddCommonHybridCache sets its defaults through the options pipeline (DependencyInjection.Caching.cs:147-161). The registration now lives in DependencyInjection.Caching.cs, and the DistributedCacheService, ICacheService and HybridCacheService anchors are refreshed. The disjoint keyspace, opt-in registration and counter-path L1 bypass are unchanged.

Revision (2026-10-06)

  • GetFromSharedStoreAsync gained a fifth caller that is a counter, not a single-use record: LoginProtectionService.CheckRegistrationRateLimitAsync reads the ADR-029 per-IP registration count through it (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Auth/LoginProtectionService.cs:138). The Decision, Rationale and Trade-offs entries now say so; the counter path's L1 bypass therefore covers this read as well as IncrementAsync.
  • The OAuth exchange-code read moved to OAuthControllerBase.cs:205.
  • Anchors re-verified against current source; the consumer examples are now MMCA.ADC.Conference.Service/Program.cs:203 and MMCA.Store.Catalog.Service/Program.cs:108 (four ADC hosts and three Store hosts, unchanged).

Revision (2026-10-07)

Re-verified against current source. The disjoint hc: keyspace, opt-in registration through the Redis-guarded wrapper, the counter-path L1 bypass, the constructor shape and the consumer adoption (four ADC hosts, three Store hosts, none in MMCA.Helpdesk) are unchanged. What moved is the GetFromSharedStoreAsync caller list, which v1.233.0 (Common #520) extended, and most line anchors.

  1. GetFromSharedStoreAsync now has seven callers in Common: v1.233.0 (#520) moved two cross-replica flag reads from GetAsync onto it, joining the four single-use records and the registration counter: LoginProtectionService.CheckLockoutAsync reads the ADR-029 lockout flag (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Auth/LoginProtectionService.cs:59), and SoftDeletedUserMiddleware reads the soft-deleted-user marker (MMCA.Common/Source/Presentation/MMCA.Common.API/Middleware/SoftDeletedUserMiddleware.cs:92). The Decision and Trade-offs entries now say so.
  2. Anchors re-verified against current source: ICacheService.cs SetAsync :75, RemoveAsync :85, RemoveByPrefixAsync :91, IncrementAsync :108, GetOrCreateAsync :148, GetFromSharedStoreAsync :65, presence check :158, stripe :162, double-check :166, CacheKeyLocks :192-195; HybridCacheService.cs class and constructor :48-53, LocalCacheDefault :66, SharedStoreReadOptions :86-91, new CacheSettings() :104, GetFromSharedStoreAsync override :154-173, RemoveByPrefixAsync :219-238 (pattern built at :233), local ceiling read at :330 and applied at :335, LoggerMessage partials :360-373; OAuthControllerBase.cs:273; LoginProtectionService.cs:141 for the registration count. The DependencyInjection.Caching.cs, DistributedCacheService.cs, CacheSettings.cs:42 and consumer Program.cs anchors are unchanged.

Revision (2026-10-21)

Re-verified against current source. The disjoint hc: keyspace, opt-in registration through the Redis-guarded wrapper, the counter-path L1 bypass, the constructor shape, the seven GetFromSharedStoreAsync callers and the consumer adoption (four ADC hosts, three Store hosts, none in MMCA.Helpdesk) are unchanged. What moved is one undocumented mechanism and most line anchors.

  1. HybridCacheService overrides TryGetAsync (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Caching/HybridCacheService.cs:174-199) with a third flag set, PresenceProbeOptions (DisableDistributedCacheWrite, :103-106), and a factory that throws a tagged KeyNotFoundException as the miss signal (:182, caught at :189). The Decision's HybridCacheService bullets now describe it.
  2. Anchors re-verified against current source: ICacheService.cs IncrementAsync :112, GetOrCreateAsync :152, presence check :162, stripe :166, double-check :170, CacheKeyLocks :196-199 (GetAsync :17, TryGetAsync :34, GetFromSharedStoreAsync :65, SetAsync :75, RemoveAsync :85, RemoveByPrefixAsync :91 unchanged); HybridCacheService.cs LocalCacheDefault :69, SharedStoreReadOptions :89-94, new CacheSettings() :119, GetFromSharedStoreAsync override :216-235, RemoveByPrefixAsync :281-300 (pattern built at :295), local ceiling read at :404 and applied at :409, LoggerMessage partials :434-447; TwoFactorAuthenticator.cs:121; DependencyInjection.Caching.cs AddCommonHybridCache :141, AddHybridCache :143, options pipeline :149-163 (host hook at :162), RemoveAll :167, factory :168-181 (settings passed at :180), wrapper :202-214 (Redis guard at :208); MMCA.ADC.Conference.Service/Program.cs:204. DistributedCacheService.cs:153, CacheSettings.cs:42, TryAddSingleton :59, MMCA.Store.Catalog.Service/Program.cs:108 and the other six caller anchors are unchanged.

Revision (2026-10-26)

Re-verified against current source. The disjoint hc: keyspace, opt-in registration through the Redis-guarded wrapper, the counter-path L1 bypass, the presence probe, the constructor shape (HybridCacheService.cs:48-53), the seven GetFromSharedStoreAsync callers and the consumer adoption (four ADC hosts, three Store hosts, none in MMCA.Helpdesk) are unchanged. Only line anchors moved.

  1. Anchors re-verified against current source: ICacheService.cs GetFromSharedStoreAsync :69, SetAsync :79, RemoveAsync :89, RemoveByPrefixAsync :95, IncrementAsync :116, GetOrCreateAsync :156, presence check :166, stripe :170, double-check :174, CacheKeyLocks :200-203 (GetAsync :17, TryGetAsync :34 unchanged); HybridCacheService.cs SharedStoreReadOptions :90-95, PresenceProbeOptions :104-107, new CacheSettings() :120, TryGetAsync override :175-200 (throwing factory :183, miss built at :383-388, caught at :190), GetFromSharedStoreAsync override :217-236, RemoveByPrefixAsync :282-301 (pattern built at :296), local ceiling read at :405 and applied at :410, LoggerMessage partials :435-448 (LocalCacheDefault :69 unchanged); EmailConfirmationTokenService.cs:95; Auth/TwoFactor/TwoFactorAuthenticator.cs:151; LoginProtectionService.cs:61 (lockout) and :143 (registration count); MMCA.ADC.Conference.Service/Program.cs:210; MMCA.Store.Catalog.Service/Program.cs:114. OAuthControllerBase.cs:273, PasswordResetTokenService.cs:128, SoftDeletedUserMiddleware.cs:92, the DependencyInjection.Caching.cs anchors, DistributedCacheService.cs:153 and CacheSettings.cs:42 are unchanged.

Revision (2026-10-28)

Re-verified against current source. The disjoint hc: keyspace, opt-in registration through the Redis-guarded wrapper, the remove-then-add registration and its order-independence (doc comment DependencyInjection.Caching.cs:138-143), the counter-path L1 bypass, the constructor shape and the consumer adoption are unchanged. Only the DependencyInjection.Caching.cs anchors moved.

  1. Every anchor in MMCA.Common/Source/Core/MMCA.Common.Infrastructure/DependencyInjection.Caching.cs moved by 16 lines in v1.262.0: one using at :1 and a RedisOutputCacheOptions PostConfigure block inside AddCaching (:60-73, the ADR-135 output-cache namespacing). That block is a Tier 2 change outside this record's scope (see the Scope note); it does not touch the hybrid substrate.
  2. Anchors re-verified against current source: DependencyInjection.Caching.cs TryAddSingleton :75, AddCommonHybridCache :157, AddHybridCache :159, options pipeline :165-179 (host hook at :178), RemoveAll :183, factory :184-197 (settings passed at :196), wrapper :218-230 (Redis guard at :224, connectionName defaulting to redis at :220).

Revision (2026-11-04)

Common v1.277.0 (Common PR #668). HybridCacheService becomes the only shared-store substrate, and prefix invalidation changes mechanism. The disjoint hc: keyspace, the counter-path L1 bypass, the GetFromSharedStoreAsync callers and the consumer adoption are unchanged.

  1. DistributedCacheService and RedisPrefixScanner are removed. AddCaching registers MemoryCacheService only, and resolving ICacheService with a non-memory IDistributedCache registered and no AddCommonHybridCache call throws, naming the call (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/DependencyInjection.Caching.cs:85-91).
  2. Generation tokens replace the SCAN (the Decision's RemoveByPrefixAsync bullet). The class is CachePrefixGenerations (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Caching/CachePrefixGenerations.cs:69, the hcg: segment at :76).
  3. Outage posture. A failed token read never fails the cache call: it falls back to the last token this process knew, or the empty baseline for a boundary it never saw, and is not retried for one local cache duration (CachePrefixGenerations.cs:354-358, :366-367, the warning at :403). Concurrent reads of one boundary share one in-flight read (:108, :288).
  4. RemoveByTagAsync is rejected. The former "Tags are deferred" section now records why: tag invalidation in Microsoft.Extensions.Caching.Hybrid 10.11.0 does not cross replicas.
  5. Boundary contract. A non-empty prefix must end at : in every store (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Caching/CachePrefixContract.cs:17-27).
  6. Anchors re-verified for the passages this revision touched: HybridCacheService.cs class :49, constructor :133-152, LocalCacheDefault :65, local ceiling read :430 and applied :435; CacheSettings.cs:47; DependencyInjection.Caching.cs constructor call :194-199, wrapper :221-233 (guard :227). The other Decision anchors (ICacheService.cs, TryGetAsync, GetFromSharedStoreAsync, the LoggerMessage partials, the registration pipeline) were not re-verified in this pass. The dated revisions above that name DistributedCacheService, RedisPrefixScanner or SCAN describe the removed design.

Revision (2026-11-23)

Re-verified against current source. The disjoint hc: keyspace, the Redis-guarded opt-in, the remove-then-add registration, the counter-path L1 bypass, the presence probe, the generation-token invalidation and the rejection of tags are unchanged. What moved is the GetFromSharedStoreAsync caller list, one keyspace mechanism the record did not describe, the constructor shape, the marker semantics, the consumer adoption path and every line anchor.

  1. Eleven GetFromSharedStoreAsync call sites. Beyond the seven recorded on 2026-10-07, the passkey challenge (MMCA.Common/Source/Core/MMCA.Common.Application/Auth/Passkeys/PasskeyChallenges.cs:74), the sign-in link token (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Auth/SignInLinks/SignInLinkTokenService.cs:104), the lockout expiry (LoginProtectionService.cs:88) and the view-as-ended marker (MMCA.Common/Source/Presentation/MMCA.Common.API/Middleware/ViewAsGuardMiddleware.cs:186) read through it. The Decision bullet and the Trade-offs entry now list them.
  2. Cross-service keys. A key starting xsvc: (MMCA.Common/Source/Core/MMCA.Common.Application/Interfaces/CrossServiceCacheKeys.cs:24-27) is qualified with the cross-service namespace and carries no generation token (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Caching/HybridCacheService.cs:442-445, CrossServiceCacheKeys.cs:20-21), so prefix invalidation does not reach it. That namespace is Cache:CrossServiceKeyPrefix, then Jwt:Audience, then the host's own namespace (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Caching/CacheKeyPrefix.cs:116-130). Two keys use it: the soft-deleted-user marker (item 4) and the view-as-ended marker, which the grant-store host writes and every other service reads (MMCA.Common/Source/Presentation/MMCA.Common.API/Middleware/ViewAsEndedMarker.cs:35-41). The keyspace section and the RemoveByPrefixAsync bullet now record the exception.
  3. Constructor shape. HybridCacheService takes a sixth optional parameter, CacheKeyNamespace? crossServiceNamespace (HybridCacheService.cs:151-157), falling back to keyNamespace (:165); the registration factory passes CacheKeyNamespace.CrossServiceFrom(sp) (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/DependencyInjection.Caching.cs:198-204).
  4. The soft-deleted-user marker means "deleted or locked". An erasure, an administrator's lock or a machine-client revocation writes it and an unlock clears it (MMCA.Common/Source/Presentation/MMCA.Common.API/Middleware/SoftDeletedUserMiddleware.cs:13-16); it is a cross-service key the Identity service writes and every service reads (MMCA.Common/Source/Core/MMCA.Common.Application/Auth/SoftDeletedUserCache.cs:68-74).
  5. Adoption runs through the service host. No ADC or Store Program.cs calls AddCommonHybridCacheWhenRedisConfigured itself: AddMmcaServiceHost calls AddRedisCaching and the wrapper on every service host (MMCA.Common/Source/Hosting/MMCA.Common.ServiceHost/ServiceHostBuilderExtensions.cs:89, :95). The host counts (four ADC, three Store, none in MMCA.Helpdesk) are unchanged.
  6. The Status "byte-identical" sentence is scoped. It holds for a memory-only host. Since v1.277.0 a host with a non-memory IDistributedCache and no AddCommonHybridCache call fails to resolve ICacheService, naming the call (DependencyInjection.Caching.cs:86-92), as the Packaging section records.
  7. Anchors re-verified against current source: ICacheService.cs RemoveByPrefixAsync :113, IncrementAsync :133, GetOrCreateAsync :173, presence check :183, stripe :187, double-check :191, CacheKeyLocks :217-221 (GetAsync :17, TryGetAsync :34, GetFromSharedStoreAsync :69, SetAsync :79, RemoveAsync :89, the WRONGTYPE remark :126-132 unchanged); HybridCacheService.cs class :55, LocalCacheDefault :71, SharedStoreReadOptions :92-97, PresenceProbeOptions :106-109, multiplexer parameter doc :142-145, new CacheSettings() :166, TryGetAsync override :224-249 (throwing factory :232, miss built at :420-425, caught at :239), GetFromSharedStoreAsync override :266-285, boundary check :335, key folding :440-448, WriteOptions :458-469 (ceiling read :461, applied :466), LoggerMessage partials :491-495; OAuthControllerBase.cs:332; TwoFactorAuthenticator.cs:197; LoginProtectionService.cs:82 (lockout) and :212 (registration count); SoftDeletedUserMiddleware.cs:95 (validator write :17-18); DependencyInjection.Caching.cs TryAddSingleton :79, AddCommonHybridCache :162, AddHybridCache :164, options pipeline :170-184 (host hook :183), RemoveAll :188, factory :189-205, wrapper :226-238 (connectionName default :228, guard :232); CachePrefixGenerations.cs generation key :281; MMCA.ADC.Conference.Service/Program.cs:82; MMCA.Store.Catalog.Service/Program.cs:32. PasswordResetTokenService.cs:128, EmailConfirmationTokenService.cs:95, CachePrefixContract.cs:17-27, CacheSettings.cs:47 and the other CachePrefixGenerations.cs anchors are unchanged. The anchors inside Revision (2026-11-04) item 3 are left as written.

ADR-026 (amended by this record: its Tier 1 substrate gains a third implementation, since 2026-11-04 its only shared-store one, its 30-second default TTL becomes the local-cache bound as well, its prefix-invalidation model becomes a generation-token write over a disjoint keyspace, and its IncrementAsync storage-format trade-off is the specific case this keyspace decision generalizes), ADR-014 (the caching decorators, which keep their own stampede protection and their cache-only-success rule and take the L1 win through GetAsync), ADR-029 (the brute-force and rate-limit counters that force IncrementAsync to bypass L1 on both legs), ADR-017 (the 24-hour idempotency records, the longest-lived entries this substrate's prefix eviction has to reach), ADR-040 (the Tier 2 output-cache edge, untouched by this record: its own store, its own tag eviction), ADR-038 (the lock-file and vulnerability-audit obligations a new package pin carries, out-of-slnx projects included), ADR-016 (the lockstep release and one-pass consumer sweep that carries this to ADC, Store, and Helpdesk).