Registry / storage / express-redis-cache

express-redis-cache

JSON →
library1.1.3jsnpmunverified

Middleware for Express apps that automatically caches HTTP responses in Redis, reducing server load and improving response times for frequently accessed routes. Version 1.1.3 is the latest stable release, with no active development since 2017. It provides a simple drop-in middleware interface and supports custom cache keys, conditional caching, and multiple Redis clients. Compared to alternatives like apicache or express-cache-controller, it uses Redis as a persistent, shared cache store suitable for distributed deployments. However, it is no longer maintained and has known issues with newer Express versions and Redis client libraries.

npm install express-redis-cache
INSTALL
IMPORT
SIG · EXPRESS-REDIS-CACH
E
express-redis-cache
storagejavascriptv1.1.3
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.

cache
const cache = require('express-redis-cache')({ host: 'localhost', port: 6379 });
const cache = require('express-redis-cache').createClient({ host: 'localhost' });
The package exports a factory function, not a class. Call with options or without arguments.
default
import cache from 'express-redis-cache';
import { cache } from 'express-redis-cache';
ESM import is not officially supported; the package is CommonJS-only. Use require() or a bundler.
cache.route
app.get('/route', cache.route(), handler);
app.get('/route', cache.route, handler);
cache.route() returns a middleware function; you must call it to pass the middleware.

Creates an Express server that caches the root route response in Redis using the express-redis-cache middleware.

const express = require('express'); const redis = require('redis'); const cacheFactory = require('express-redis-cache'); const app = express(); const redisClient = redis.createClient({ host: process.env.REDIS_HOST || '127.0.0.1', port: process.env.REDIS_PORT || 6379 }); const cache = cacheFactory({ client: redisClient, prefix: 'myapp' }); app.get('/', cache.route('home'), (req, res) => { res.send('Hello World!'); }); app.listen(3000, () => console.log('Server running on port 3000'));
Debug
Known issues
deprecatedPackage has not been updated since 2017 and is no longer maintained. It may have security vulnerabilities and compatibility issues with newer versions of Express and Node.js.
fix
Consider migrating to actively maintained alternatives like apicache or express-cache-controller.
affects: all
breakingThe package depends on redis@2.x, which is deprecated and may not work with newer Redis server versions or Node.js TLS changes.
fix
Force install redis@3 or higher by overriding in package.json, though compatibility is not guaranteed.
affects: >=1.0.0
gotchaCache entry names are always prefixed; the default prefix is 'express-redis-cache' unless overridden. Forgetting this can cause cache key collisions.
fix
Set a custom prefix via the constructor options: { prefix: 'myapp' }
affects: all
gotchaThe cache.route() function must be called with parentheses, even with no arguments. Omitting the call returns the function itself, not the middleware.
fix
Always invoke cache.route() as cache.route() or cache.route('name')
affects: all
breakingExpress 4.x introduced changes to res.json() that may not be handled correctly by this middleware; cached responses may be incomplete.
fix
Use res.send() instead of res.json() for routes that are cached, or patch the middleware.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server is not running or incorrect host/port specified.
fix
Start Redis server: redis-server, or verify REDIS_HOST and REDIS_PORT environment variables.
TypeError: cache.route is not a function
Common mistake: calling cacheFactory without parentheses, so cache is the factory function instead of the cache instance.
fix
Correct: const cache = require('express-redis-cache')({ host: 'localhost' });
Warning: express-redis-cache - no redis client connected. Bypassing cache.
Redis client not created or connection failed; the middleware falls through, serving uncached requests.
fix
Ensure Redis is running and the client is properly configured: require('express-redis-cache')({ client: redis.createClient() })
Error: Redis connection to 127.0.0.1:6379 failed - getaddrinfo ENOTFOUND
Hostname 'localhost' cannot be resolved (e.g., in some Docker environments).
fix
Use '127.0.0.1' instead of 'localhost' in the host option.
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies
redisrequiredRequired for connecting to Redis server. The package uses redis@2.x by default.
Agent activity
27 hits · last 30 days
node
26
Resources