Use when implementing Apollo caching strategies including cache policies, optimistic UI, cache updates, and normalization.
View on GitHubTheBushidoCollective/han
jutsu-apollo-graphql
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-apollo-graphql/skills/apollo-caching-strategies/SKILL.md -a claude-code --skill apollo-caching-strategiesInstallation paths:
.claude/skills/apollo-caching-strategies/# Apollo Caching Strategies
Master Apollo Client's caching mechanisms for building performant applications
with optimal data fetching and state management strategies.
## Overview
Apollo Client's intelligent cache is a normalized, in-memory data store that
allows for efficient data fetching and updates. Understanding cache policies
and management strategies is crucial for building high-performance apps.
## Installation and Setup
### Cache Configuration
```javascript
// apollo/cache.js
import { InMemoryCache, makeVar } from '@apollo/client';
export const cache = new InMemoryCache({
typePolicies: {
Query: {
fields: {
posts: {
// Pagination with offset
keyArgs: ['filter'],
merge(existing = [], incoming, { args }) {
const merged = existing.slice(0);
const offset = args?.offset || 0;
for (let i = 0; i < incoming.length; i++) {
merged[offset + i] = incoming[i];
}
return merged;
}
}
}
},
Post: {
keyFields: ['id'],
fields: {
comments: {
merge(existing = [], incoming) {
return [...existing, ...incoming];
}
}
}
},
User: {
keyFields: ['email'],
fields: {
fullName: {
read(_, { readField }) {
return `${readField('firstName')} ${readField('lastName')}`;
}
}
}
}
}
});
```
## Core Patterns
### 1. Fetch Policies
```javascript
// Different fetch policies for different use cases
import { useQuery } from '@apollo/client';
import { GET_POSTS } from './queries';
// cache-first (default): Check cache first, network if not found
function CacheFirstPosts() {
const { data } = useQuery(GET_POSTS, {
fetchPolicy: 'cache-first'
});
return <PostsList posts={data?.posts} />;
}
// cache-only: Never make network request, cache or error
function CacheOnlyPosts() {
const { data }