Skip to content

v4: multilayer storage adapter pattern#12

Merged
grischaerbe merged 1 commit into
nextfrom
grischaerbe/v4-adapters
Apr 28, 2026
Merged

v4: multilayer storage adapter pattern#12
grischaerbe merged 1 commit into
nextfrom
grischaerbe/v4-adapters

Conversation

@grischaerbe
Copy link
Copy Markdown
Owner

Summary

  • Replace the single in-memory store with a composable IStorageAdapter contract: reads cascade L1 → Ln, hits back-fill missing layers preserving storedAt, and writes synthesize meta on L1 then propagate to deeper layers using the same storedAt.
  • Required adapters constructor option; ship a built-in MemoryAdapter; add an optional namespace prefix; expose a TMeta generic for typed sidecar metadata; delete/clear/isCached become async; keys() is removed; any adapter throw rejects remember() (strict mode).
  • IStorageAdapter.read returns { value: T } | undefined so adapters can store undefined values without colliding with the absence signal.

Test plan

  • npm run typecheck (root) and npx tsc --noEmit -p tests/tsconfig.json
  • npm run eslint plus eslint over tests
  • npm test — 53 tests across 5 suites: cascade behavior, strict error propagation, dedup, namespace, MemoryAdapter, fetchPolicies, index

🤖 Generated with Claude Code

Replace the single in-memory store with a composable IStorageAdapter
contract: reads cascade L1 → Ln, hits back-fill missing layers preserving
storedAt, and writes synthesize meta on L1 then propagate to deeper
layers. Adapters are required at construction; clear/delete/isCached
become async; keys() is removed; an optional namespace prefix isolates
instances that share an adapter; Cacheables gains a TMeta generic for
typed sidecar metadata. Ships a built-in MemoryAdapter and refines
read() to return { value } | undefined so adapters can store undefined
values without colliding with the absence signal.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant