feat: add runtime-controlled request-local caching#52
Draft
lan17 wants to merge 3 commits into
Draft
Conversation
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.
Summary
Adds an opt-in request-local cache layer whose lifetime is the outermost enabled DialCache scope. Runtime policy can enable it per invocation with
requestLocal: true, while existing local and Redis TTL/ramp behavior remains unchanged.Closes #51 — #51
Architecture and design
Request lifetime
enable()creates a lightweight request holder.enable()anddisable()calls reuse that holder while retaining async-scope-local enabled state.requestLocal: true.Runtime policy
DialCacheKeyConfignow accepts optionalrequestLocal?: boolean; the compatibility default is off.CacheLayerenum.Lookup and coalescing
Only active portions of the chain participate:
undefinedis preserved with membership-based lookup semantics.Both value maps and flight maps continue to use the existing canonical
DialCacheKey.urn. This deliberately avoids changing key encoding in this PR; the centralized typed-key work remains tracked by #14.Invalidation, retention, and ownership
invalidateRemote()does not evict or fence request-local or process-local values.The broader ownership test matrix remains tracked by #18.
API and observability
DialCacheKeyConfig.requestLocal.request_localwithout adding request-local policy toCacheLayeror expanding the root value exports.request_local | processto custom adapter labels.dialcache_coalesced_counter{use_case,key_type}schema.dialcache_scoped_coalesced_counter{use_case,key_type,scope}.layer="request_local".Metric evolution and config observability follow-ups remain tracked by:
Documentation and maintainer tooling
pnpm benchmark:request-localmaintainer command for sequential request-local hits plus request- and process-scoped fan-out.Validation
Run with Node v22.22.0:
corepack pnpm checkcorepack pnpm test:integrationcorepack pnpm benchmark:request-localgit diff --check