0.16.1 • Published 2 years ago

apollo3-cache-persist-encrypt v0.16.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

This library is based on apollo3-cache-persist. It have added option to use encryption during persistance. This solution was taken from apollo-cache-persist-encrypt, but it was renewed for apollo3. There was also added option to encryptByKey (here it is good to write your own persisting function). And to use white list for encryption.

More info on encrypting by key Encrypting by key

apollo3-cache-persist npm version build status 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,
  ...
});

See a complete example in the React Native example.

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 😁.

0.15.4

2 years ago

0.15.5

2 years ago

0.15.6

2 years ago

0.15.7

2 years ago

0.16.0

2 years ago

0.16.1

2 years ago

0.14.0

3 years ago

0.13.0

3 years ago