MCPcopy Index your code
hub / github.com/apollographql/apollo-cache-persist

github.com/apollographql/apollo-cache-persist @0.15.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.15.0 ↗ · + Follow
156 symbols 295 edges 35 files 3 documented · 2% updated 29d ago0.15.0 · 2024-03-27★ 1,42020 open issues

Browse by type

Functions 105 Types & classes 51
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

apollo3-cache-persist npm version Commitizen friendly

Simple persistence for all Apollo Client 3.0 cache implementations, including InMemoryCache and Hermes.

Supports web and React Native. See all storage providers.

Basic Usage

npm install --save apollo3-cache-persist

or

yarn add apollo3-cache-persist

To get started, simply pass your Apollo cache and an underlying storage provider to persistCache.

By default, the contents of your Apollo cache will be immediately restored (asynchronously, see how to persist data before rendering), and will be persisted upon every write to the cache (with a short debounce interval).

Examples

React Native

import AsyncStorage from '@react-native-async-storage/async-storage';
import { InMemoryCache } from '@apollo/client/core';
import { persistCache, AsyncStorageWrapper } from 'apollo3-cache-persist';

const cache = new InMemoryCache({...});

// await before instantiating ApolloClient, else queries might run before the cache is persisted
await persistCache({
  cache,
  storage: new AsyncStorageWrapper(AsyncStorage),
});

// Continue setting up Apollo as usual.

const client = new ApolloClient({
  cache,
  ...
});

Web

import { InMemoryCache } from '@apollo/client/core';
import { persistCache, LocalStorageWrapper } from 'apollo3-cache-persist';

const cache = new InMemoryCache({...});

// await before instantiating ApolloClient, else queries might run before the cache is persisted
await persistCache({
  cache,
  storage: new LocalStorageWrapper(window.localStorage),
});

// Continue setting up Apollo as usual.

const client = new ApolloClient({
  cache,
  ...
});

See a complete example in the web example.

Contributing

Want to make the project better? Awesome! Please read through our Contributing Guidelines.

Maintainers

We all do this for free... so please be nice 😁.

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Method 96
Class 38
Interface 13
Function 9

Languages

TypeScript100%

Modules by API surface

src/persistCacheSync.ts13 symbols
src/CachePersistor.ts11 symbols
src/storageWrappers/SessionStorageWrapper.ts10 symbols
src/storageWrappers/MMKVStorageWrapper.ts10 symbols
src/storageWrappers/LocalStorageWrapper.ts10 symbols
src/storageWrappers/LocalForageWrapper.ts10 symbols
src/storageWrappers/IonicStorageWrapper.ts10 symbols
src/storageWrappers/AsyncStorageWrapper.ts10 symbols
src/Log.ts10 symbols
src/storageWrappers/MMKVWrapper.ts7 symbols
src/Trigger.ts7 symbols
src/Storage.ts7 symbols

For agents

$ claude mcp add apollo-cache-persist \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page