You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
staleTime: 5_000, // ms (optional, default: Infinity)
263
+
staleTime: 5_000, // ms (optional, default: undefined)
264
+
cacheTime: 30_000, // ms (optional, default: undefined, no time-based eviction)
264
265
deduplicate: true, // boolean (optional, default: true when cache is set)
265
266
},
266
267
})
@@ -275,6 +276,7 @@ const team = $.resource("team", {
275
276
- status (idle/pending/ready/failed)
276
277
- stale flag
277
278
- staleTime timer
279
+
- cacheTime timer
278
280
- in-flight promise (for deduplication)
279
281
280
282
The `ResourceRef` always reflects the **active key** entry — the key from the most recent `load()` or `reload()` call.
@@ -309,12 +311,12 @@ Key semantics:
309
311
-`invalidate()` marks only the active entry stale.
310
312
-`cache.deduplicate` deduplicates per active key.
311
313
-`cache.staleTime` timers are per key.
314
+
-`cache.cacheTime` timers are per key.
312
315
- Resources without `cache.key` behave exactly as before (single-entry behavior).
313
316
314
-
Scope limitations (Phase 2):
317
+
Scope limitations (Phase 2 + Phase 3):
315
318
316
319
-**Single-runtime only.** Keyed entries live in one `ResourceNode` within one `ScreenRuntime`.
317
-
-**No `cacheTime`.** Entries persist for the node's lifetime. No time-based eviction.
318
320
-**No SWR.** Stale data must be explicitly reloaded.
319
321
-**No cross-navigation cache.** Disposing the runtime clears all entries.
320
322
-**No dependency-tracked keys.** Key is derived from context at load time; automatically reacting to context changes is future work.
@@ -336,6 +338,42 @@ Behavior:
336
338
-**`dispose()`** clears all stale timers and prevents late notifications.
337
339
-**With `cache.key`**, each key has an independent stale timer.
338
340
341
+
### cacheTime (Phase 3)
342
+
343
+
`cache.cacheTime` is an optional number in milliseconds controlling how long a stale entry's value is retained before eviction. Default is `undefined` (no time-based eviction).
344
+
345
+
`cacheTime` starts when an entry becomes stale — from `invalidate()`, action invalidation, or `staleTime` expiry.
346
+
347
+
Before `cacheTime` expires:
348
+
-`status` remains `"ready"`
349
+
-`value` remains available
350
+
-`stale` is `true`
351
+
352
+
When `cacheTime` expires (active entry eviction):
353
+
-`status` → `"idle"`
354
+
-`value` → `undefined`
355
+
-`error` → `undefined`
356
+
-`stale` → `false`
357
+
- Subscribers are notified
358
+
359
+
When `cacheTime` expires (inactive keyed entry eviction):
360
+
- Entry is removed from the internal map
361
+
- No subscriber notification
362
+
363
+
Behavior:
364
+
-**`load()`/`reload()`** clears the cacheTime timer, clears stale, starts a fresh load.
365
+
-**Successful load** clears the cacheTime timer (no longer stale).
366
+
-**Failed load** does NOT start cacheTime (preserves existing failure behavior).
367
+
-**`dispose()`** clears all cacheTime timers.
368
+
-**With `cache.key`**, each key has an independent cacheTime timer.
369
+
-**Works without `staleTime`** — manual `invalidate()` is sufficient to start cacheTime.
370
+
-**`cacheTime: 0`** evicts on the next event loop tick after staleness.
371
+
372
+
Scope limitations (Phase 3):
373
+
-**Single-runtime only.** cacheTime does not survive runtime disposal.
374
+
-**No SWR.** Eviction does not trigger automatic reload.
375
+
-**No cross-navigation cache.** Disposing the runtime clears all entries.
376
+
339
377
### deduplicate
340
378
341
379
`cache.deduplicate` is an optional boolean. When `true`, concurrent `load()` and `reload()` calls while a load is already pending share the same in-flight promise:
@@ -354,7 +392,6 @@ When `cache` is not set at all, deduplication is disabled to preserve backward c
354
392
355
393
The following cache options remain as future work and are **not yet supported**:
356
394
357
-
-**`cacheTime`** — retention period for stale values before eviction
0 commit comments