withCacheTtl method

Context withCacheTtl(
  1. Duration? ttl
)

Creates a new context with the specified cache TTL.

This overrides the default TTL for a single request.

Example:

// Cache for 1 hour instead of default
final response = await client.execute(
  query,
  context: Context().withCacheTtl(Duration(hours: 1)),
);

// Cache indefinitely (no expiration)
final response = await client.execute(
  query,
  context: Context().withCacheTtl(null),
);

Implementation

Context withCacheTtl(Duration? ttl) {
  return ttl != null ? withEntry(CacheTtlEntry(ttl)) : this;
}