Skip to content

feat: add inline getOrLoad API#84

Merged
lan17 merged 2 commits into
mainfrom
agent/get-or-load
Jul 24, 2026
Merged

feat: add inline getOrLoad API#84
lan17 merged 2 commits into
mainfrom
agent/get-or-load

Conversation

@lan17

@lan17 lan17 commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • add loader-first DialCache.getOrLoad(load, options) and exported GetOrLoadOptions<Value> for one-shot inline cache blocks
  • route both cached() and getOrLoad() through one internal cache-execution primitive while preserving stable-use-case registration semantics
  • document direct-key/captured-value requirements and cover local, Redis, invalidation, coalescing, fail-open, type, and packed-package behavior

Why

cached(fn, options) is ergonomic for extracted reusable functions, but immediately invoking a newly wrapped function is awkward for inline work and conflicts with unique useCase registration. getOrLoad() keeps the loader inline, permits repeated calls with one bounded stable useCase, 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 check on Node 22.22.0: strict types, 261 unit tests with coverage, ESM/CommonJS builds and declarations, packed runtime/declaration consumers
  • corepack pnpm test:package on Node 20.17.0
  • corepack pnpm test:integration: 69 live Redis 6.2, Valkey 8, node-redis, Valkey GLIDE, and Redis Cluster cases
  • corepack pnpm benchmark:request-local: all semantic assertions passed
  • corepack pnpm audit --prod --audit-level high: no known vulnerabilities
  • git diff --check

@lan17
lan17 marked this pull request as ready for review July 24, 2026 05:21
@lan17
lan17 merged commit 2e1b856 into main Jul 24, 2026
5 checks passed
@lan17
lan17 deleted the agent/get-or-load branch July 24, 2026 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an ergonomic getOrLoad() API for inline cache blocks

1 participant