How does client-side caching work with Apollo Client's normalized cache?
Answer
Apollo Client's InMemoryCache normalizes all query results into a flat key-value store where each object is stored by a unique cache key (default: TypeName:id, e.g., User:42). When multiple queries return the same User object, they all reference the same cache entry — updating it in one query automatically updates it everywhere. The cache's read and write methods enable optimistic UI: write the expected result before the mutation completes, then reconcile with the actual server response. Field policies customize how fields are read/written — for example, the keyArgs option controls which arguments are included in the cache key for paginated fields. Cache policies (cache-first, cache-and-network, network-only, no-cache) control staleness behavior. The Apollo Client DevTools extension lets you inspect, search, and modify the cache at runtime.
Previous
How do you implement distributed tracing across GraphQL resolvers?
Next
How do you scale GraphQL subscriptions using Redis pub/sub?
More GraphQL Questions
View all →- Advanced What is Apollo Federation and how do subgraphs, gateways, and directives like @key and @extends work?
- Advanced What is incremental delivery in GraphQL with @defer and @stream?
- Advanced How do you implement query cost analysis and rate limiting in a production GraphQL API?
- Advanced What is schema evolution and deprecation strategy in GraphQL?
- Advanced What is the Relay specification for GraphQL — Node interface, Connection/Edge pagination?