Course contentsShow
← Web Development
Lesson 1561 of 2,98228. GraphQL FundamentalsFree lesson

Apollo Cache Fundamentals

Learn how Apollo's normalized cache works, cache keys, and why it prevents redundant network requests.

Apollo Cache Fundamentals

What you'll learn: How Apollo Client stores and reuses GraphQL data locally to avoid redundant network requests.

Understanding Apollo's Normalized Cache

When you fetch data with Apollo Client, it doesn't just display the results and forget them. Apollo stores that data in an in-memory cache using a clever normalization strategy.

Think of it like a smart filing cabinet: instead of keeping complete copies of every document you've ever read, you file each unique piece of information once, then reference it whenever needed.

How Cache Keys Work

Apollo creates a cache key for each object by combining its __typename and id (or _id) field:

// Apollo sees this object in a query response:
{ __typename: 'User', id: '123', name: 'Alice' }

// And stores it with the key: "User:123"

When another query requests User:123, Apollo instantly returns it from cache instead of hitting the network. No duplicate request needed!

Why This Prevents Redundant Requests

Imagine you query a user's profile, then later query a list of posts where that same user is the author. Apollo recognizes User:123 from cache and returns it immediately for the posts query—even though these were separate operations.

Without normalization, each query would store its own copy of the user data and require separate network requests.

Objects Without IDs

If an object lacks an id or _id field, Apollo can't normalize it and stores it inline with its parent query. This means it won't be reused across queries.

Key Takeaway: Apollo's normalized cache stores objects by unique keys (__typename:id), enabling instant retrieval across queries and dramatically reducing network requests by reusing already-fetched data.