description Apollo Cache (Client-Side) Overview
This refers to the sophisticated caching layer within Apollo Client itself. It stores normalized data based on IDs, meaning if multiple components request the same User ID, Apollo serves the cached object instantly without hitting the network again. This is crucial for preventing redundant API calls when a user navigates between components that share common data entities.
help Apollo Cache (Client-Side) FAQ
What does Apollo Client's normalized cache actually store?
Apollo Client's InMemoryCache stores GraphQL results as normalized records keyed by identity fields such as an object's `id` and `__typename`. If two components request the same User record, Apollo can reuse the normalized object instead of downloading a duplicate response.
What happens when Apollo Client uses a cache-first fetch policy?
With `cache-first`, Apollo checks whether the requested fields are already available in the client cache before sending a network request. A missing field, an explicit `network-only` policy, or an invalidated record can cause the query to reach the server.
How do typePolicies affect Apollo Cache behavior?
Type policies define identity fields, field merge rules, and pagination behavior for types in the cache. For example, a policy can tell Apollo how to identify a User by a stable key or how to merge pages of a GraphQL connection instead of overwriting earlier results.
How should a mutation update Apollo's client-side cache?
A mutation can return the changed object with its `id` and `__typename`, allowing Apollo to merge the result into the normalized cache. For list membership or deletion, the UI may also need an explicit cache update, an eviction, or a targeted refetch so stale references disappear.
explore Explore More
Similar to Apollo Cache (Client-Side)
See all arrow_forwardReviews & Comments
Write a Review
Be the first to review
Share your thoughts with the community and help others make better decisions.