Registry / storage / apollo-cache-persist-dev

apollo-cache-persist-dev

JSON →
library0.2.1jsnpmunverified

apollo-cache-persist-dev (v0.2.1) is a development preview of apollo-cache-persist, providing simple persistence for Apollo Client 2.0+ cache implementations including InMemoryCache and Hermes. It supports web (localStorage) and React Native (AsyncStorage) with automatic restore on app start and persistence on cache writes. Key features include configurable triggers (write, background), debounce, max size limits, and serialization. This dev package includes experimental changes and community PRs not yet merged into the stable release, with potential breaking changes. Alternative to manual cache serialization.

npm install apollo-cache-persist-dev
INSTALL
IMPORT
SIG · APOLLO-CACHE-PERSI
A
apollo-cache-persist-dev
storagejavascriptv0.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

persistCache
import { persistCache } from 'apollo-cache-persist-dev'
import persistCache from 'apollo-cache-persist-dev'
PersistCache is a named export, not a default export.
CachePersistor
import { CachePersistor } from 'apollo-cache-persist-dev'
import { CachePersistor } from 'apollo-cache-persist'
CachePersistor may not be available in the stable apollo-cache-persist package. Check imports carefully.
persistCache (CommonJS)
const { persistCache } = require('apollo-cache-persist-dev')
const persistCache = require('apollo-cache-persist-dev')
CommonJS require with destructuring for named export.

Shows how to persist an InMemoryCache to localStorage using persistCache with key and debug options.

import { InMemoryCache } from 'apollo-cache-inmemory'; import { persistCache } from 'apollo-cache-persist-dev'; const cache = new InMemoryCache(); await persistCache({ cache, storage: window.localStorage, key: 'my-cache-key', debug: true, }); const client = new ApolloClient({ cache, uri: 'https://api.example.com/graphql', });
Debug
Known issues
breakingPackage name change from 'apollo-cache-persist' to 'apollo-cache-persist-dev' might cause confusion if you accidentally use the stable package.
fix
Use the correct package name in package.json and imports.
affects: >=0.2.0
deprecatedAsyncStorage from @react-native-community/async-storage is deprecated in favor of @react-native-async-storage/async-storage.
fix
Use @react-native-async-storage/async-storage for React Native.
affects: >=0.2.0
gotchaPersistCache() must be awaited before creating ApolloClient, otherwise queries might execute before cache is restored.
fix
Always await persistCache() before new ApolloClient(...).
affects: >=0.0.0
gotchaThe 'background' trigger only works on React Native, not web. If used on web, persistence will not occur.
fix
Use 'write' trigger on web, or provide a custom trigger.
affects: >=0.0.0
breakingMax size defaults to 1 MB. If exceeded, cache is truncated and app starts cold. This may cause unexpected data loss.
fix
Set maxSize: false for unlimited or increase limit as needed.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: persistCache is not a function
Importing as default export instead of named export.
fix
Change to: import { persistCache } from 'apollo-cache-persist-dev'
Cannot find module '@react-native-community/async-storage' or its corresponding type declarations.
Missing peer dependency for React Native storage.
fix
npm install @react-native-community/async-storage or switch to @react-native-async-storage/async-storage.
PersistCache is not a constructor (e.g., new persistCache())
Using new on persistCache which is a function, not a class.
fix
Use: persistCache({...}) without new.
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies
@react-native-community/async-storageoptionalRequired for React Native storage, but the package itself is a peer dependency.
apollo-cache-inmemoryoptionalPeer dependency for using with InMemoryCache (or Hermes).
Agent activity
49 hits · last 30 days
node
43
Resources
apollo-cache-persist-dev — npm install apollo-cache-persist-dev · libregistry