feat: add inline getOrLoad API#84
Merged
Merged
Conversation
lan17
marked this pull request as ready for review
July 24, 2026 05:21
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
DialCache.getOrLoad(load, options)and exportedGetOrLoadOptions<Value>for one-shot inline cache blockscached()andgetOrLoad()through one internal cache-execution primitive while preserving stable-use-case registration semanticsWhy
cached(fn, options)is ergonomic for extracted reusable functions, but immediately invoking a newly wrapped function is awkward for inline work and conflicts with uniqueuseCaseregistration.getOrLoad()keeps the loader inline, permits repeated calls with one bounded stableuseCase, and preserves the existing cache pipeline.Impact
This is an additive public API. Existing callers, cache-key bytes, Redis data and scripts, invalidation identity, adapters, metrics labels, dependency ownership, and
cached()duplicate-registration behavior are unchanged.Closes #71
Validation
corepack pnpm checkon Node 22.22.0: strict types, 261 unit tests with coverage, ESM/CommonJS builds and declarations, packed runtime/declaration consumerscorepack pnpm test:packageon Node 20.17.0corepack pnpm test:integration: 69 live Redis 6.2, Valkey 8, node-redis, Valkey GLIDE, and Redis Cluster casescorepack pnpm benchmark:request-local: all semantic assertions passedcorepack pnpm audit --prod --audit-level high: no known vulnerabilitiesgit diff --check