An HTTP-compliant route path middleware for serving cached responses with invalidation for Node.js. Version 2.10.8 supports Node >=12 and is actively maintained (frequent releases). It provides a framework-agnostic caching layer for SSR, with built-in LRU cache, automatic TTL-based invalidation, and stale-while-revalidate support. Unlike simple in-memory caches, it integrates cache status headers (MISS, HIT, EXPIRED, BYPASS, STALE) and works with any HTTP server framework. Key differentiators: focus on SSR caching, auto-invalidation, and easy integration with Express, Fastify, or raw http.
npm install cacheable-responseNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a basic HTTP server using cacheable-response as middleware, caching a JSON response for 1 minute.
Use `res.end()` or `res.json()` depending on the framework. For Express, `res.json(data)` works if you include `express` context.
Provide a custom `cacheKey` function in the options to normalize URLs, e.g., strip query params or sort them.
Remove the `compress` option from the factory options. Compression is now handled externally if needed.
Ensure TTL is in milliseconds. For 1 hour, use `3600000`.
Change to `const cacheableResponse = require('cacheable-response')`Ensure `get` returns an object like `{ data: ..., ttl: ... }`Kill the process using the port or change the port number.