Policy enum
Caching policies that determine how Syncache.get retrieves data.
Each policy defines a different strategy for balancing between cached data and fresh network fetches.
Values
- offlineFirst → const Policy
-
Returns cached data if available and not expired; fetches otherwise.
This is the default policy and provides the best offline-first experience. The cache is checked first, and network requests are only made when necessary.
Behavior:
- If valid (non-expired) cache exists, return it immediately
- If online, attempt to fetch fresh data
- If fetch fails but stale cache exists, return stale data
- If no cache and offline/fetch fails, throw CacheMissException
- cacheOnly → const Policy
-
Returns only cached data; never makes network requests.
Use this policy when you want to ensure no network activity, such as displaying data that was pre-fetched earlier.
Throws CacheMissException if no cached data exists.
- networkOnly → const Policy
-
Always fetches from network; ignores cached data.
Use this policy when you need guaranteed fresh data and network availability is certain.
Throws if the network request fails.
- refresh → const Policy
-
Fetches from network if online; falls back to cache if offline.
Similar to offlineFirst but always prefers fresh data when online, regardless of cache validity.
Behavior:
- If online, fetch from network
- If offline, return cached data
- If offline with no cache, throw CacheMissException
- staleWhileRefresh → const Policy
-
Returns cached data immediately; refreshes in background if expired.
This policy provides the fastest perceived performance by always returning cached data first, then updating the cache asynchronously. Subscribers via Syncache.watch will receive the updated value.
Behavior:
- If cache exists, return it immediately
- If cache is expired and online, trigger background refresh
- If no cache exists and online, fetch and return
- If no cache and offline, throw CacheMissException
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