setQueryData<T> method

void setQueryData<T>(
  1. Object queryKey,
  2. T updater(
    1. T? oldData
    )
)

Functionally update cached data for a query.

updater receives the previous data and returns new data. Automatically sets the timestamp to now.

Implementation

void setQueryData<T>(Object queryKey, T Function(T? oldData) updater) {
  final normalizedKey = QueryKey.normalize(queryKey);
  final oldData = getCachedData<T>(normalizedKey);
  final newData = updater(oldData);

  updateCache(normalizedKey, newData, DateTime.now());
}