Registry / devops / koa-cache-lite

koa-cache-lite

JSON →
library3.8.8jsnpmunverified

A zero-dependency Koa router cache middleware (v3.8.8, stable). Provides in-memory and optional Redis-based caching with route-specific timeout configuration, increasing cache timeout based on request frequency, and customizable cache key fragments from headers or query parameters. Key differentiators: no dependencies, simple API with configure/middleware/clear, support for cluster environments, and fine-grained cache key control.

npm install koa-cache-lite
INSTALL
IMPORT
SIG · KOA-CACHE-LITE
K
koa-cache-lite
devopsjavascriptv3.8.8
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
var cache = require('koa-cache-lite')
import cache from 'koa-cache-lite'
CommonJS only; no ESM or default export.
configure
cache.configure({ '/route': 1000 }, { debug: true })
cache({ timeout: 1000 })
configure replaces the old init API; first argument is routes object.
middleware
koa.use(cache.middleware())
koa.use(cache.middleware)
middleware() returns a function; must be called.

Sets up in-memory caching for /api/v1/test with a 3-second timeout and debug logging.

var cache = require('koa-cache-lite'); var Koa = require('koa'); var app = new Koa(); cache.configure({ '/api/v1/test': 3000 }, { debug: true }); app.use(cache.middleware()); app.listen(1337);
Debug
Known issues
breakingBreaking API changes in v3.x: cache.configure() replaces old cache() call. Second argument is now options object.
fix
Migrate to cache.configure(routes, options). Routes is an object mapping URL patterns to timeouts, options includes debug, external, increasing, etc.
affects: <3.0.0
gotchacache.middleware() must be called as a function. Passing cache.middleware directly to app.use will not work.
fix
Use app.use(cache.middleware())
affects: >=3.0.0
gotchaWhen using Redis, you must manually install ioredis npm package. It is not included as a dependency.
fix
npm install ioredis
affects: >=3.0.0
deprecatedThe 'routes' property within options is deprecated. Use routes as first argument instead.
fix
Pass routes object directly: cache.configure({ '/url': timeout }, options)
affects: >=3.0.0
gotchaCache key customization using 'x-key' header requires 'keyFragment' option set to 'cache' (the header field name). The default is 'x-cache-key'?
fix
Set options.keyFragment to the header name that contains the cache key fragment.
affects: >=3.0.0
gotchaIn cluster mode, cache.clear() may not work across workers unless middleware is properly wrapped with init().
fix
Use cache.init() in master and pass wrapped middleware to workers.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: koa.use is not a function
Using Koa v2+ where app.use is a method returning an app, but trying to use 'koa' as a function.
fix
Use const Koa = require('koa'); const app = new Koa(); app.use(cache.middleware());
Error: Cannot find module 'ioredis'
Trying to use Redis cache without installing ioredis.
fix
npm install ioredis
TypeError: cache.middleware is not a function
Importing module incorrectly (e.g., import version) or using old API.
fix
Use const cache = require('koa-cache-lite'); app.use(cache.middleware());
Upgrade
Version history
3.8.8latest on npm
Audit
Dependencies
ioredisoptionalRequired for Redis cache support
Agent activity
3 hits · last 30 days
node
2
Bingbot
1
Resources