Remote / foldkit-remote

Retention and garbage collection

Remote is a cache, so it should be allowed to forget facts no active feature needs.

Data.subscriptions derives retention roots from the active Surfaces of every call on the domain, so a call's retain entry never collects what another call reads; connections given to any call are kept the same way. A root keeps:

  • the entities and fields its Projection requires;
  • referenced targets reached by nested selections;
  • retained connections and the selected fields of their visible items;
  • data touched by pending optimistic work.

After the configured grace period, RetentionChanged enters the Model and the pure Remote reducer collects what no root reaches. The roots it keeps are the active ones and those of the Surfaces left, so going back to a page shows what it held rather than reading Loading, within Remote.make's budget.

The budget counts entries: each row and each list the store holds is one. The rows and lists the active Surfaces read, and what a pending write changes (with the rows of a list it places a row in), are always kept, even past it. The roots a Surface left, which leave together, are kept newest first while the entries they add fit; the first that does not fit is evicted with every older one. A read whose row another root holds already costs one, so the roots kept stay bounded too. The default is defaultBudget, 1,000. A list or row the budget evicted reads Initial again, and why names it Evicted rather than Missing. A hand-wired Remote.retain takes budget in its options.

When a Surface is left, its lists stay held stale (or keep their age under staleWhileRevalidate) and its reads remain cached. Returning shows those rows as Refreshing while the planner refetches stale lists—unless you return via Back/Forward within historyWindow, which shows Ready immediately without fetching. Once a page leaves past budget, it is evicted oldest-first and the next visit reads Loading and refetches.

A value nothing reached when retention ran, such as a prefetch no Surface showed, is still collected at once. Collecting is safe because the server remains authoritative and the planner can refetch.

This is another important difference from Sync: Remote recovery may discard and refetch; Sync recovery must preserve unsent client intent.