apollo-cache-lite
A lightweight cache implementation for Apollo Client.
Features
- 🚀 Lightweight - Supports the most frequently used use-cases: SSR, extracting cache state, restoring cache state in browser, reading fragments from cache
- 🔥 Fast - Read/write performance is the top priority to make your Apollo app faster
- 🚨 Beta - Use it carefully, it's not production ready yet!
Getting started
- Install with npm or yarn:
npm i --save apollo-cache-lite
yarn add apollo-cache-lite
- Import in your app:
import { ApolloClient } from 'apollo-client';
import { ApolloCacheLite } from 'apollo-cache-lite';
const client = new ApolloClient({
cache: new ApolloCacheLite(),
});
Options
The ApolloCacheLite constructor takes an optional configuration object to customize the cache:
getIdFromObject
A function that takes a data object and returns a unique identifier.
import { ApolloCacheLite, getDefaultIdFromNode } from 'apollo-cache-lite';
const cache = new ApolloCacheLite({
getIdFromObject(object) {
switch (object.__typename) {
case 'foo': return object.key;
case 'bar': return `bar:${object.blah}`;
default: return getDefaultIdFromNode(object);
}
}
});