queueHydration method

void queueHydration(
  1. Object key,
  2. dynamic data, {
  3. DateTime? updatedAt,
})

Enqueue a pre-deserialized value to be injected into the typed cache on the first typed API call (fetchQuery, watchQuery, etc.) for key.

This is the shared hydration mechanism used by PersistQoraClient and SsrHydrator. Prefer those higher-level APIs unless you are building a custom hydration source.

The actual injection is deferred to avoid Dart's sound type-system cast failure: a CacheEntry<dynamic> cannot be cast to CacheEntry<T> at runtime unless the entry was originally created as CacheEntry<T>. By calling _applyPendingHydration<T> at the first typed call site, the entry is created with the correct T from the start.

data must be the already-deserialized Dart object (not raw JSON). updatedAt is used for stale-time calculation: defaults to epoch (always stale, triggers SWR revalidation on first mount).

Implementation

void queueHydration(
  Object key,
  dynamic data, {
  DateTime? updatedAt,
}) {
  final normalized = normalizeKey(key);
  final pk = _encodePendingKey(normalized);
  _pendingHydration[pk] = (data: data, updatedAt: updatedAt);
  _log('Hydration queued: $normalized');
}