Registry / database / koa-redis-cache

koa-redis-cache

JSON →
library3.0.3jsnpmunverified

A Koa middleware for caching HTTP responses in Redis. Version 3.0.3 is the latest stable release. The package allows developers to easily cache responses for specified routes with configurable expiration times, customizable Redis key prefixes, and exclusion patterns. It supports per-route expire settings and sets a custom `X-Koa-Redis-Cache` header when serving from cache. Compared to other Koa caching middleware, it is lightweight and Redis-specific, but note it is not actively maintained.

npm install koa-redis-cache
INSTALL
IMPORT
SIG · KOA-REDIS-CACHE
K
koa-redis-cache
databasejavascriptv3.0.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.

default
import cache from 'koa-redis-cache'
const cache = require('koa-redis-cache')
ESM default import; CommonJS require also works but ESM is preferred.
cache (as function)
const cache = require('koa-redis-cache')
import { cache } from 'koa-redis-cache'
This package exports a function via default export; named export 'cache' does not exist.
TypeScript types
import cache from 'koa-redis-cache'
import * as cache from 'koa-redis-cache'
Types are not bundled; for TypeScript use a type definition like @types/koa-redis-cache (if available) or declare module.

Sets up Koa with redis cache middleware for route /index with 60-second expiration.

import Koa from 'koa'; import cache from 'koa-redis-cache'; const app = new Koa(); const options = { expire: 60, routes: ['/index'] }; app.use(cache(options)); app.use(async (ctx) => { ctx.body = 'Hello World'; }); app.listen(3000);
Debug
Known issues
gotchaNo built-in TypeScript type definitions; requires @types/koa-redis-cache or manual typing.
fix
Install @types/koa-redis-cache or create a declaration file.
affects: >=3.0.0
deprecatedPackage uses node_redis which is deprecated in favor of ioredis.
fix
Use ioredis or consider alternative like koa-redis-cache-io.
affects: >=3.0.0
breakingRedis port and host configuration moved to `redis.port` and `redis.host` in v3.
fix
Wrap redis options under `redis` object: { redis: { port: 6379, host: 'localhost' } }.
affects: >=3.0.0
Errors
Common errors & fixes
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server is not running or not reachable.
fix
Start Redis server or configure correct host/port in options.
TypeError: cache is not a function
Using default import as named import or wrong require style.
fix
Use `const cache = require('koa-redis-cache')` or `import cache from 'koa-redis-cache'`.
Upgrade
Version history
3.0.3latest on npm
Audit
Dependencies
koarequiredpeer dependency for Koa 2.x middleware
redisrequiredrequired for Redis client
Agent activity
2 hits · last 30 days
node
2
Resources
koa-redis-cache — npm install koa-redis-cache · libregistry