Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

apollo-cache-persist

> 前端框架
Open source

Simple persistence for all Apollo Cache implementations

1.4K stars0 likes0 views
WebsiteGitHub

About

Simple persistence for all Apollo Cache implementations

apollo3-cache-persist

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
    • React Native
    • Web
  • Storage Providers
  • Advanced Usage
  • FAQ
  • Contributing
  • Maintainers

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 .

  • @wtrocki
  • @wodCZ
  • @jspizziri

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptapollographqlofflinereact-native

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架