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

apollo-link-local-cache

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-link-local-cache

Apollo Link that facilitates locally storing query results

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Build Status coverage npm version sponsored by Taller

Purpose

An Apollo Link that facilitates locally storing query results via interception of responses.

Installation

yarn add apollo-link-local-cache

Usage

import { LocalCacheLink } from 'apollo-link-local-cache'

const link = new LocalCacheLink()

Options

LocalCacheLink takes an object with the following options to allow customization of it's behavior:

namevaluedefaultrequired
shouldCachebooleanFunctiontrue
generateKeyFunctionoperation.toKeyfalse
storageObjectFunctionlocalStorage in the browser
normalizeFunctionJSON.stringifyfalse
shouldCache

The cache policy. When set to true defaults to cache all. When set to a callback, will receive the operation as argument, and should return true or false. Defaults to true.

generateKey

A callback to generate a key for an operation. Defaults to using operation.toKey.

storage

The Storage in use. Will default to window.localStorage when available. Can also be a callback, in which case it will be called with the current operation and should retrieve a valid storage.

normalize

Normalization callback, which receives the operation. Executed prior to storing a query result.

denormalize

Denormalization callback, which receives the operation. Executed after retrieving a cached query result from the store.

hasLocalDirective

A special shouldCache implementation is available for enabling caching of queries which use the @local directive. Use it as follows:

import {
  LocalCacheLink,
  hasLocalDirective as shouldCache,
} from 'apollo-link-local-cache'

const link = new LocalCacheLink({ shouldCache })

Context

The LocalCacheLink does not use the context for anything, but customization of the config options will often receive the full operation, meaning they can achieve their purpose by using the context if necessary.

Keywords

FAQs

Package last updated on 17 Oct 2018

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