withCache method

Context withCache({
  1. CachePolicy? policy,
  2. Duration? ttl,
})

Creates a new context with both cache policy and TTL.

This is a convenience method that combines withCachePolicy and withCacheTtl.

Example:

final response = await client.execute(
  query,
  context: Context().withCache(
    policy: CachePolicy.cacheFirst,
    ttl: Duration(minutes: 30),
  ),
);

Implementation

Context withCache({
  CachePolicy? policy,
  Duration? ttl,
}) {
  var context = this;
  if (policy != null) context = context.withCachePolicy(policy);
  if (ttl != null) context = context.withCacheTtl(ttl);
  return context;
}