Registry / database / undici-cache-redis

undici-cache-redis

JSON →
library1.0.1jsnpmunverified

A Redis-backed cache store for undici's cache interceptor, enabling HTTP response caching with Redis. Version 1.0.1 provides features like cache invalidation by tags, client-side caching (tracking cache), and support for managed Redis environments. Built on iovalkey for optimal Redis/Valkey connectivity. It integrates seamlessly with undici's interceptor pipeline and offers a separate RedisCacheManager for advanced cache monitoring and management. Compared to alternatives, it focuses on high performance and flexibility, making it suitable for production Node.js applications that require distributed caching.

npm install undici-cache-redis
INSTALL
IMPORT
SIG · UNDICI-CACHE-REDIS
U
undici-cache-redis
databasejavascriptv1.0.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.

RedisCacheStore
import { RedisCacheStore } from 'undici-cache-redis'
const RedisCacheStore = require('undici-cache-redis').RedisCacheStore
ESM-only package; named import required.
RedisCacheManager
import { RedisCacheManager } from 'undici-cache-redis'
import RedisCacheManager from 'undici-cache-redis'
Named export, not default.
RedisCacheStore (with require)
const { RedisCacheStore } = require('undici-cache-redis')
const RedisCacheStore = require('undici-cache-redis')
Must destructure; no default export.

Creates a Redis cache store and composes it with undici's cache interceptor to cache HTTP GET requests.

import { Agent, interceptors } from 'undici' import { RedisCacheStore } from 'undici-cache-redis' const store = new RedisCacheStore({ clientOpts: { host: process.env.REDIS_HOST ?? 'localhost', port: parseInt(process.env.REDIS_PORT ?? '6379'), keyPrefix: 'my-app:cache:' } }) const agent = new Agent() .compose(interceptors.cache({ store })) const response = await agent.request({ origin: 'https://api.example.com', method: 'GET', path: '/users/123' }) console.log(await response.body.text())
Debug
Known issues
breakingVersion 1.0.0 requires Node.js >= 18 or 20 due to undici dependencies.
fix
Upgrade Node.js to 18 or 20.
affects: <1.0.0
gotchaThe 'cacheTagsHeader' option must match the header sent by the upstream server; otherwise, tag-based invalidation won't work.
fix
Ensure the server includes a header (e.g., 'Cache-Tags') and set 'cacheTagsHeader' to that header name.
affects: >=0.0.0
deprecatedUsing 'clientOpts' without TLS for production Redis is not recommended; use TLS URLs or set tls: true.
fix
Use a Redis URL with 'rediss://' or configure TLS options.
affects: >=0.0.0
gotchaThe 'keyPrefix' option is passed to iovalkey's createClient; it may be ignored if the client is already created externally.
fix
If providing a pre-configured client, set keyPrefix on that client instead.
affects: >=0.0.0
Errors
Common errors & fixes
ERR_MODULE_NOT_FOUND: Cannot find package 'undici-cache-redis'
Package not installed or import path is incorrect.
fix
npm install undici-cache-redis && ensure using ESM import syntax.
TypeError: store.deleteTags is not a function
Calling deleteTags on a store instance that does not have the method (likely using a different store type).
fix
Ensure you have instantiated RedisCacheStore from 'undici-cache-redis'.
Error: connect ECONNREFUSED 127.0.0.1:6379
Redis server is not running on localhost:6379.
fix
Start a Redis server or set REDIS_HOST/REDIS_PORT environment variables to point to a running instance.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
25 hits · last 30 days
node
20
Meta
2
OpenAI (training)
1
Resources
undici-cache-redis — npm install undici-cache-redis · libregistry