feat(core): resource cache phase 2 — cache.key#123
Merged
Conversation
Adds ResourceKey type and cache.key option for resource cache keying. - cache.key derives a resource entry key from the current load context - One ResourceNode holds multiple internal entries, one per key - Each entry independently tracks value, error, status, stale flag, staleTime timer, and in-flight promise - ResourceRef proxies the active key entry - cache.staleTime timers are per key - cache.deduplicate deduplicates per active key - Resources without cache.key behave exactly as before Reverts .changeset/pre.json to exclude the new changeset from the prerelease consumed list (entries in pre.json changesets are treated as already consumed; the source of truth is the .md file itself).
… API mismatch - Replace JSON.stringify normalizeKey with encodeResourceKey (type-tagged) - Tagged approach preserves null vs undefined vs 'null' vs 'undefined', NaN, Infinity, -Infinity, -0, and nested array distinctions - Fix docs/Resources.md: key() -> cache.key() nested API - Fix proposal doc examples to match nested API - Add 8 new tests for key serialization edge cases - Update PR body to remove .changeset/pre.json references
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
cache.key— an optional function that derives a cache key from the resource load context. Each unique key gets its own independent entry (value, status, error, stale flag, staleTime timer, in-flight promise) within a singleResourceNode.API Added
ResourceKeytype:string | number | boolean | null | undefined | ResourceKey[]cache.key?: (context: ResourceLoadContext<TServices>) => ResourceKeyoptionKey Serialization
Keys are normalized via a type-tagged encoder (
encodeResourceKey) wrapped inJSON.stringifyfor stableMap<string, Entry>lookups. The tagged approach preserves distinctions betweennull,undefined,"null","undefined",0,-0,NaN,Infinity,-Infinity, and nested arrays — unlike plainJSON.stringifywhich would collapse many of these.Equivalent array content (e.g.
["a", "b"]) maps to the same entry.Runtime Behavior
Not Implemented (Phase 2 Scope)
cacheTime— no time-based evictionValidation
Changeset
.changeset/tricky-terms-doubt.md— patch for@intent-framework/core. This is the source of truth for the unreleased change.Note:
.changeset/pre.jsonis not changed in the final diff. The prerelease-state issue was fixed before opening/finalizing the PR —tricky-terms-doubtwas never committed as consumed inpre.json.Changed Files
packages/core/src/resource.ts— main implementationpackages/core/src/screen.ts— type updatepackages/core/src/index.ts— exportResourceKeypackages/core/src/core.test.ts— 27 new test casesdocs/Resources.md— public docs updatedocs/proposals/Resource-Cache-And-Stale-Semantics.md— status update.changeset/tricky-terms-doubt.md— changeset (source of truth)