withCachePolicy method
Creates a new context with the specified cache policy.
This overrides the default cache policy for a single request.
Example:
// Force fresh data from network
final response = await client.execute(
query,
context: Context().withCachePolicy(CachePolicy.networkOnly),
);
// Use cache only, don't fetch from network
final response = await client.execute(
query,
context: Context().withCachePolicy(CachePolicy.cacheOnly),
);
Implementation
Context withCachePolicy(CachePolicy policy) {
return withEntry(CachePolicyEntry(policy));
}