CacheContextExtension extension

Extension methods for Context to configure cache behavior per-request.

These extensions provide a fluent API for overriding cache policies and TTL values on a per-request basis.

Example:

// Override cache policy for a single request
final response = await client.execute(
  query,
  context: Context().withCachePolicy(CachePolicy.networkOnly),
);

// Override both policy and TTL
final response = await client.execute(
  query,
  context: Context().withCache(
    policy: CachePolicy.cacheFirst,
    ttl: Duration(hours: 1),
  ),
);
on
  • Context

Methods

cacheAndNetwork() → Context

Available on Context, provided by the CacheContextExtension extension

Returns cached data immediately, then fetches fresh data.
cacheOnly() → Context

Available on Context, provided by the CacheContextExtension extension

Forces the request to use only cached data.
withCache({CachePolicy? policy, Duration? ttl}) → Context

Available on Context, provided by the CacheContextExtension extension

Creates a new context with both cache policy and TTL.
withCachePolicy(CachePolicy policy) → Context

Available on Context, provided by the CacheContextExtension extension

Creates a new context with the specified cache policy.
withCacheTtl(Duration? ttl) → Context

Available on Context, provided by the CacheContextExtension extension

Creates a new context with the specified cache TTL.
withoutCache() → Context

Available on Context, provided by the CacheContextExtension extension

Disables caching for this request.