What is the difference between network-only, cache-first, and cache-and-network fetch policies?
Answer
Apollo Client's fetch policies control how queries interact with the cache. cache-first (default): read from cache; only fetch from network if data is not cached. Best for stable data. network-only: always fetch from network; result is stored in cache for future queries but cache is never used for the current query. Best for frequently changing critical data. cache-and-network: returns cached data immediately (fast render), then fetches from network and updates if data changed. Good balance for most use cases. no-cache: always fetch from network; result is NOT stored in cache. For sensitive/one-off queries. cache-only: only read from cache; error if not cached. For offline-first apps. standby: like cache-first but doesn't update on cache changes. Set per query: useQuery(QUERY, { fetchPolicy: 'network-only' }).
Previous
What are Apollo Client hooks and how do you use them?
Next
How do you update the Apollo cache after a mutation?
More GraphQL Questions
View all →- Intermediate How do you implement pagination in GraphQL?
- Intermediate What is the Relay specification in GraphQL?
- Intermediate How do you implement authorization in GraphQL resolvers?
- Intermediate What is graphql-shield and how does it work?
- Intermediate How do you implement real-time subscriptions with GraphQL?