feat(core): implement resource cache phase 1 - staleTime and deduplicate#119
Merged
Conversation
Add ResourceCacheOptions with staleTime (time-based staleness) and deduplicate (in-flight load deduplication). Resources without cache options behave exactly as before. - staleTime: optional ms timer that marks resource stale after successful load; resets on reload; cleared on dispose; failed loads do not start timer - deduplicate: optional boolean (default true when cache set); concurrent load/reload calls share a single in-flight promise - dispose(): new ResourceNode method to clean up stale timers - ScreenRuntime.dispose() now calls node.dispose() on all nodes Validation: pnpm test (384 all pass), typecheck, build, lint, pack:check, changeset status
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
Implement resource cache semantics phase 1:
cache.staleTimeandcache.deduplicate.API
Behavior
cache.staleTime: After a successful load/reload, a timer starts. When it fires, the resource becomes stale —stalecondition fires, status stays"ready", value stays available. Resets on every successful load/reload. Failed loads do not start the timer.dispose()clears the timer.cache.deduplicate: Whentrue(default whencacheis set), concurrentload()/reload()calls while a load is pending share a single in-flight promise. Only one loader invocation runs. Whenfalse, preserves current independent concurrent behavior. Resources withoutcacheoptions are unaffected.Changed files
packages/core/src/resource.ts— newResourceCacheOptionstype,cacheonResourceConfig,disposeonResourceNode, staleTime/deduplicate logicpackages/core/src/screen.ts— builder acceptscacheoptionpackages/core/src/runtime.ts— passescachetocreateResourceNode, callsnode.dispose()packages/core/src/index.ts— exportResourceCacheOptionspackages/core/src/core.test.ts— 13 new tests covering staleTime, deduplicate, error/dispose edge casesdocs/Resources.md— cache options section with phase-1 docs and future-work calloutdocs/proposals/Resource-Cache-And-Stale-Semantics.md— implementation status notes.changeset/seven-cobras-tan.md— patch changeset for coreValidation
pnpm --filter @intent-framework/core test✅ (174 pass)pnpm test✅ (384 pass across all packages)pnpm typecheck✅pnpm build✅pnpm lint✅pnpm pack:check✅pnpm changeset status✅Not implemented (still future)
cache.keycacheTimeswr