Registry / storage / apollo-cache-persist

apollo-cache-persist

JSON →
library0.1.1jsnpmunverified

Simple persistence for all Apollo Client 2.x cache implementations, including InMemoryCache and Hermes. Version 0.1.1 (GitHub: apollographql/apollo-cache-persist). Supports web (localStorage) and React Native (AsyncStorage). Released with no major updates since initial version. Key differentiators: hooks into Apollo cache writes with debounce, supports custom triggers (background, write, custom function), provides a CachePersistor class for manual control. Does not support Apollo Client 3.x (use apollo3-cache-persist for that).

npm install apollo-cache-persist
INSTALL
IMPORT
SIG · APOLLO-CACHE-PERSI
A
apollo-cache-persist
storagejavascriptv0.1.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';
const persistCache = require('apollo-cache-persist');
Package ships types but is ESM/CJS hybrid. Named export.
CachePersistor
import { CachePersistor } from 'apollo-cache-persist';
import CachePersistor from 'apollo-cache-persist';
Named export, not default.
PersistedData
import type { PersistedData } from 'apollo-cache-persist';
TypeScript type export. Use type import.

Shows the basics of persisting an Apollo InMemoryCache to localStorage with apollo-cache-persist.

import { InMemoryCache } from 'apollo-cache-inmemory'; import { persistCache } from 'apollo-cache-persist'; const cache = new InMemoryCache(); persistCache({ cache, storage: window.localStorage, }).then(() => { // Continue setting up Apollo as usual. });
Debug
Known issues
breakingPackage is deprecated for Apollo Client 3.x. Use apollo3-cache-persist instead.
fix
If using Apollo Client 3+, migrate to apollo3-cache-persist.
affects: >=0.1
deprecatedApollo Client 2.x is no longer actively maintained. Consider upgrading to Apollo Client 3+.
fix
Update to Apollo Client 3 and use apollo3-cache-persist.
affects: >=0.1
gotchaMax cache size default is 1MB. Exceeding will pause persistence and cause cold start on next launch.
fix
Set maxSize: false for unlimited, or increase as needed.
affects: >=0.1
gotchaBackground trigger only works on React Native, not web.
fix
Use 'write' or custom trigger for web.
affects: >=0.1
gotchaserialize option defaults to true. If your storage already serializes, set serialize: false to avoid double serialization.
fix
Set serialize: false if using a storage provider that handles serialization.
affects: >=0.1
Errors
Common errors & fixes
Failed to persist cache: [object Object] is not a function
Using an incompatible storage provider (e.g., window.localStorage is not directly supported unless wrapped).
fix
Ensure storage matches the expected interface: getItem, setItem, removeItem.
TypeError: Cannot read property 'restore' of undefined
Cache instance not passed correctly or is undefined.
fix
Pass a valid Apollo Cache instance as the 'cache' option.
Module not found: Can't resolve 'apollo-cache-persist'
Package not installed. Or using TypeScript without proper module resolution.
fix
Install with 'npm install apollo-cache-persist' and ensure tsconfig has 'node' moduleResolution.
Warning: Persisted data size exceeds maxSize. Pausing persistence.
Cache contents exceed the default 1 MB limit.
fix
Increase maxSize or set to false for unlimited size.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
47 hits · last 30 days
node
40
OpenAI (training)
1
Resources
apollo-cache-persist — npm install apollo-cache-persist · libregistry