Socket
Socket
Sign inDemoInstall

apollo-server-caching

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-server-caching

[![npm version](https://badge.fury.io/js/apollo-server-caching.svg)](https://badge.fury.io/js/apollo-server-caching) [![Build Status](https://circleci.com/gh/apollographql/apollo-server/tree/main.svg?style=svg)](https://circleci.com/gh/apollographql/apoll


Version published
Maintainers
1
Created

What is apollo-server-caching?

The apollo-server-caching package provides a set of utilities for implementing caching in Apollo Server. It includes interfaces and classes for creating and managing caches, which can help improve the performance of your GraphQL server by reducing the need to repeatedly fetch the same data.

What are apollo-server-caching's main functionalities?

InMemoryLRUCache

The InMemoryLRUCache class provides an in-memory cache with a Least Recently Used (LRU) eviction policy. This is useful for caching data that is frequently accessed but can be evicted when the cache reaches its size limit.

const { InMemoryLRUCache } = require('apollo-server-caching');

const cache = new InMemoryLRUCache();

// Set a value in the cache
cache.set('key', 'value');

// Get a value from the cache
cache.get('key').then(value => console.log(value));

// Delete a value from the cache
cache.delete('key');

PrefixingKeyValueCache

The PrefixingKeyValueCache class allows you to add a prefix to all keys in a base cache. This is useful for namespacing cache entries to avoid key collisions.

const { PrefixingKeyValueCache, InMemoryLRUCache } = require('apollo-server-caching');

const baseCache = new InMemoryLRUCache();
const cache = new PrefixingKeyValueCache(baseCache, 'prefix:');

// Set a value in the cache with a prefix
cache.set('key', 'value');

// Get a value from the cache with a prefix
cache.get('key').then(value => console.log(value));

Errors and Cache

The package provides error handling mechanisms for cache operations. This ensures that your application can gracefully handle scenarios where cache operations fail.

const { InMemoryLRUCache } = require('apollo-server-caching');

const cache = new InMemoryLRUCache();

// Set a value in the cache
cache.set('key', 'value').catch(error => console.error('Error setting cache:', error));

// Get a value from the cache
cache.get('key').then(value => console.log(value)).catch(error => console.error('Error getting cache:', error));

Other packages similar to apollo-server-caching

FAQs

Package last updated on 05 Nov 2021

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