cacheAndNetwork method

Context cacheAndNetwork()

Returns cached data immediately, then fetches fresh data.

Equivalent to withCachePolicy(CachePolicy.cacheAndNetwork). Use with client.stream() to receive both responses.

Example:

client.stream(
  query,
  context: Context().cacheAndNetwork(),
).listen((response) {
  // First: cached data (if available)
  // Second: fresh network data
  updateUI(response.data);
});

Implementation

Context cacheAndNetwork() {
  return withCachePolicy(CachePolicy.cacheAndNetwork);
}