CachePolicy enum
Defines the caching strategy for GraphQL requests.
Each policy determines how the cache and network are used to fulfill requests.
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:
- Check cache
- If found and not expired, return cached data
- 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:
- Attempt network fetch
- If successful, cache and return the result
- 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:
- Check cache
- If found and not expired, return cached data
- 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:
- Fetch from network
- Cache the result
- 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:
- If cached data exists, return it immediately
- Fetch from network in parallel
- 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.