# apollo3-cache-persist

> Simple persistence for all Apollo cache implementations

Latest version **0.15.0** (published 2024-03-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install apollo3-cache-persist
pnpm add apollo3-cache-persist
yarn add apollo3-cache-persist
bun add apollo3-cache-persist
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; declining downloads.

## Facts

| | |
|---|---|
| Version | 0.15.0 |
| Published | 2024-03-26 |
| First published | 2020-06-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 331.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1419 |
| Author | James Reggio |
| Maintainers | wodcz, benjamn, wtrocki, hwillson, apollo-bot |

## Links

- npm: https://www.npmjs.com/package/apollo3-cache-persist
- Repository: https://github.com/apollographql/apollo-cache-persist
- Homepage: https://github.com/apollographql/apollo-cache-persist#readme
- Issues: https://github.com/apollographql/apollo-cache-persist/issues
- npm.io page: https://npm.io/package/apollo3-cache-persist

## Recent versions

- 0.15.0 (latest) — 2024-03-26
- 0.14.1 — 2022-07-04
- 0.14.0 — 2022-02-08
- 0.13.0 — 2021-09-17
- 0.12.1 — 2021-08-12
- 0.12.0 — 2021-08-12
- 0.11.0 — 2021-07-29
- 0.10.0 — 2021-07-05
- 0.9.1 — 2020-11-24
- 0.9.0 — 2020-11-23
- 0.8.0 — 2020-10-19
- 0.7.0 — 2020-10-15
- 0.6.0 — 2020-09-29
- 0.5.0 — 2020-09-26
- 0.4.0 — 2020-09-26
- … 2 more at https://npm.io/package/apollo3-cache-persist/versions

## README

# apollo3-cache-persist [![npm version](https://badge.fury.io/js/apollo3-cache-persist.svg)](https://badge.fury.io/js/apollo3-cache-persist) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

Simple persistence for all Apollo Client 3.0 cache implementations, including
[`InMemoryCache`][0] and [`Hermes`][1].

Supports web and React Native. [See all storage providers.](./docs/storage-providers.md)

[0]: https://github.com/apollographql/apollo-client/tree/master/src/cache/inmemory
[1]: https://github.com/convoyinc/apollo-cache-hermes


- [Basic Usage](#basic-usage)
  - [React Native](#react-native)
  - [Web](#web)
- [Storage Providers](./docs/storage-providers.md)
- [Advanced Usage](./docs/advanced-usage.md)
- [FAQ](./docs/faq.md)
- [Contributing](#contributing)
- [Maintainers](#maintainers)

## Basic Usage

```sh
npm install --save apollo3-cache-persist
```

or

```sh
yarn add apollo3-cache-persist
```

To get started, simply pass your Apollo cache and an
[underlying storage provider](./docs/storage-providers.md) to `persistCache`.

By default, the contents of your Apollo cache will be immediately restored
(asynchronously, see [how to persist data before rendering](./docs/faq.md#how-do-i-wait-for-the-cache-to-be-restored-before-rendering-my-app)), and will be persisted upon every write to the cache (with a
short debounce interval).

### Examples

#### React Native

```js
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

```js
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](./examples/web/src/App.tsx).

## Contributing

Want to make the project better? Awesome! Please read through our [Contributing Guidelines](./CONTRIBUTING.md).

## Maintainers

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

- [@wtrocki](https://github.com/wtrocki)
- [@wodCZ](https://github.com/wodCZ)
- [@jspizziri](https://github.com/jspizziri)

---
_Source: https://npm.io/package/apollo3-cache-persist · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
