CachePolicy enum

Defines the caching strategy for GraphQL requests.

Each policy determines how the cache and network are used to fulfill requests.

Inheritance
Available extensions

Values

cacheFirst → const CachePolicy

Return cached data if available, otherwise fetch from network.

This is the most common policy for read operations. It provides fast responses when data is cached while ensuring fresh data on cache misses.

Flow:

  1. Check cache
  2. If found and not expired, return cached data
  3. If not found, fetch from network and cache the result
networkFirst → const CachePolicy

Fetch from network first, fallback to cache on error.

Use this when you want fresh data but need a fallback for offline scenarios.

Flow:

  1. Attempt network fetch
  2. If successful, cache and return the result
  3. If network fails, return cached data if available
cacheOnly → const CachePolicy

Only return cached data, never fetch from network.

Use this for offline-only scenarios or when you know data is already cached.

Flow:

  1. Check cache
  2. If found and not expired, return cached data
  3. If not found, return null/error (no network request)
networkOnly → const CachePolicy

Always fetch from network, update cache.

Use this when you need guaranteed fresh data (e.g., after mutations).

Flow:

  1. Fetch from network
  2. Cache the result
  3. Return the result
cacheAndNetwork → const CachePolicy

Return cached data immediately, then fetch and update.

Use this for optimistic UI updates where you want instant feedback followed by fresh data.

Flow:

  1. If cached data exists, return it immediately
  2. Fetch from network in parallel
  3. When network responds, cache and return updated data

Properties

hashCode int
The hash code for this object.
no setterinherited
index int
A numeric identifier for the enumerated value.
no setterinherited
name String

Available on Enum, provided by the EnumName extension

The name of the enum value.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

values → const List<CachePolicy>
A constant List of the values in this enum, in order of their declaration.