Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo3-cache-persist

Package Overview
Dependencies
Maintainers
5
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo3-cache-persist

Simple persistence for all Apollo cache implementations

  • 0.15.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
212K
decreased by-6.5%
Maintainers
5
Weekly downloads
 
Created

What is apollo3-cache-persist?

The apollo3-cache-persist package is used to persist and rehydrate the Apollo Cache in JavaScript applications. This is particularly useful for offline support and improving the performance of your application by caching GraphQL query results.

What are apollo3-cache-persist's main functionalities?

Persist Cache

This feature allows you to persist the Apollo Cache to a storage medium, such as localStorage. This ensures that the cache is saved and can be rehydrated when the application is reloaded.

const { persistCache } = require('apollo3-cache-persist');
const { InMemoryCache } = require('@apollo/client');
const cache = new InMemoryCache();

persistCache({
  cache,
  storage: window.localStorage,
});

Rehydrate Cache

This feature allows you to rehydrate the Apollo Cache from a storage medium. This is useful for restoring the cache state when the application is reloaded, providing a seamless user experience.

const { persistCache } = require('apollo3-cache-persist');
const { InMemoryCache } = require('@apollo/client');
const cache = new InMemoryCache();

persistCache({
  cache,
  storage: window.localStorage,
}).then(() => {
  // Now the cache is rehydrated and ready to use
});

Custom Storage

This feature allows you to use a custom storage solution for persisting the Apollo Cache. You can define your own getItem, setItem, and removeItem methods to integrate with any storage system.

const { persistCache } = require('apollo3-cache-persist');
const { InMemoryCache } = require('@apollo/client');
const cache = new InMemoryCache();

const customStorage = {
  getItem: async (key) => { /* custom get item logic */ },
  setItem: async (key, value) => { /* custom set item logic */ },
  removeItem: async (key) => { /* custom remove item logic */ },
};

persistCache({
  cache,
  storage: customStorage,
});

Other packages similar to apollo3-cache-persist

FAQs

Package last updated on 26 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc