The `koa-cache-control` package provides Koa middleware for declarative management of HTTP `Cache-Control` headers. Currently stable at version 2.0.0, it offers a simple API to configure caching behaviors, including `no-cache`, `max-age`, `public`, `private`, and `no-store`. The package helps consolidate common caching patterns, such as automatically setting `max-age=0` when `no-cache` is enabled. While its release cadence has been relatively slow, with its last major update aligning with Koa 2.x, it specifically targets Koa applications, providing a more integrated approach than manually manipulating headers directly. It supports both Koa 1.x (generator-based) and Koa 2.x (async/await based) applications.
npm install koa-cache-controlVerified import paths — ran on the pinned version, not inferred.
Sets up a basic Koa application using `koa-cache-control` with default settings and demonstrates dynamic override on specific routes.
Rewrite generator functions to async/await syntax: `app.use(async (ctx, next) => { /* ... */ await next(); });`Be aware of option interactions. If `no-cache` is desired but with a specific `max-age` or other directives, manually construct the header or ensure `noCache` is not set.
Always set `ctx.cacheControl` at the beginning of your route handler or before calling `await next()` if you need to modify caching behavior based on subsequent logic.
Ensure you have `import Koa from 'koa'; const app = new Koa();` and that `app` is correctly instantiated before using `.use()`.
Verify `app.use(cacheControl(...))` is called early in your middleware chain. Check for other middleware or manual `ctx.set('Cache-Control', ...)` calls that might conflict. Inspect the generated header using browser developer tools or `curl -v`.No dependency data recorded yet.