You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@apollo/utils.keyvaluecache

Package Overview
Dependencies
Maintainers
4
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollo/utils.keyvaluecache

Minimal key-value cache interface

4.0.0
latest
Source
npmnpm
Version published
Weekly downloads
2.2M
2.59%
Maintainers
4
Weekly downloads
 
Created

What is @apollo/utils.keyvaluecache?

@apollo/utils.keyvaluecache is a utility package provided by Apollo that offers a simple and efficient key-value caching mechanism. It is designed to be used in conjunction with Apollo Server and other Apollo tools to improve performance by caching frequently accessed data.

What are @apollo/utils.keyvaluecache's main functionalities?

Basic Key-Value Storage

This feature allows you to store and retrieve key-value pairs in an in-memory cache. The example demonstrates setting a value for a key and then retrieving it.

const { InMemoryLRUCache } = require('@apollo/utils.keyvaluecache');

const cache = new InMemoryLRUCache();

async function cacheData() {
  await cache.set('key', 'value');
  const value = await cache.get('key');
  console.log(value); // Outputs: 'value'
}

cacheData();

Expiration Time

This feature allows you to set a time-to-live (TTL) for cached items. The example demonstrates setting a value with a TTL of 1 second and then attempting to retrieve it after 2 seconds, resulting in a null value.

const { InMemoryLRUCache } = require('@apollo/utils.keyvaluecache');

const cache = new InMemoryLRUCache();

async function cacheDataWithTTL() {
  await cache.set('key', 'value', { ttl: 1 }); // TTL in seconds
  setTimeout(async () => {
    const value = await cache.get('key');
    console.log(value); // Outputs: null
  }, 2000);
}

cacheDataWithTTL();

Deleting Cache Entries

This feature allows you to delete specific entries from the cache. The example demonstrates setting a value, deleting it, and then attempting to retrieve it, resulting in a null value.

const { InMemoryLRUCache } = require('@apollo/utils.keyvaluecache');

const cache = new InMemoryLRUCache();

async function deleteCacheEntry() {
  await cache.set('key', 'value');
  await cache.delete('key');
  const value = await cache.get('key');
  console.log(value); // Outputs: null
}

deleteCacheEntry();

Other packages similar to @apollo/utils.keyvaluecache

Keywords

apollo

FAQs

Package last updated on 21 May 2025

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