Registry / devops / express-aggressive-cache

express-aggressive-cache

JSON →
library2.1.6jsnpmunverified

Express middleware for aggressive yet obedient HTTP response caching with support for in-memory and Redis stores. Current stable version is 2.1.6, released as a mature library with TypeScript types included. Key differentiators: it caches by default unless Cache-Control explicitly forbids it, respects s-maxage over max-age, provides purge API by cache tag, and sets x-cache headers for hit/miss visibility. Built for Node >=8, it is fully tested and suitable for API/SRR caching with plug-and-play setup.

npm install express-aggressive-cache
INSTALL
IMPORT
SIG · EXPRESS-AGGRESSIVE
E
express-aggressive-cache
devopsjavascriptv2.1.6
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 'express-aggressive-cache'
const cache = require('express-aggressive-cache')
Package provides a default export which is a function that returns an object with middleware and purge.
memoryStore
import { memoryStore } from 'express-aggressive-cache'
const memoryStore = require('express-aggressive-cache').memoryStore
Named export for in-memory store options, available since v2. For CJS use destructuring require.
CacheInstance
import type { CacheInstance } from 'express-aggressive-cache'
TypeScript type for the cache object returned by the default function.

Shows basic usage with default in-memory store, 1-hour max age, and application-wide caching.

import express from 'express'; import cache from 'express-aggressive-cache'; const app = express(); const myCache = cache({ maxAge: 3600, store: 'memory' }); app.use(myCache.middleware); app.get('/hello', (req, res) => { res.json({ message: 'Hello World' }); }); app.listen(3000, () => console.log('Server running on port 3000'));
Debug
Known issues
gotchaBy default, responses without Cache-Control headers are cached indefinitely (maxAge defaults to Infinity).
fix
Set maxAge explicitly to avoid unbounded memory usage. In v2 onwards, default maxAge is still Infinity; always configure a limit.
affects: <2.0.0
breakingVersion 2.0.0 changed the API: cache() now returns an object with middleware and purge, not a middleware function directly.
fix
Update from app.use(cache()) to app.use(cache().middleware).
affects: >=2.0.0
deprecatedThe option 'cacheControl' was deprecated in v2.1.0 and removed in v2.2.0.
fix
Use Cache-Control headers on responses instead.
affects: >=2.1.0 <2.2.0
gotchaIn-memory store uses LRU eviction; long keys can consume significant memory.
fix
Consider using Redis store for large-scale apps or set a reasonable max limit for memoryStore.
affects: >=1.0.0
gotchaThe purge function is async but does not wait for internal memory cleanup; it may take up to a minute to free memory.
fix
Do not rely on immediate memory after purge; use for cache invalidation only.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: cache(...) is not a function
Using require in an ESM context or forgetting to call cache() as a function.
fix
Use import cache from 'express-aggressive-cache' and then cache().middleware.
Cannot find module 'express-aggressive-cache'
Package not installed or missing from node_modules.
fix
Run npm install express-aggressive-cache
Property 'middleware' does not exist on type 'CacheInstance'
Using an older version (<2.0.0) that returned a middleware function directly.
fix
Update package to >=2.0.0 and access .middleware property.
Error: store must be an instance of Store
Passing an invalid store object to cache() options.
fix
Use either 'memory' (string) or a custom store that implements the Store interface (e.g., from 'express-aggressive-cache/store/redis').
Upgrade
Version history
2.1.6latest on npm
Audit
Dependencies
expressrequiredMiddleware is designed to work with Express.js framework.
Agent activity
2 hits · last 30 days
node
2
Resources
express-aggressive-cache — npm install express-aggressive-cache · libregistry