cache-control
Returns pre-computed Cache-Control response header tuples. The
directive string is built at factory time, so there is zero per-request
overhead. Accepts either a raw directive string or structured options.
Pipeline stage: Cross-cutting
Import
Section titled “Import”import { cacheControl } from "@centralping/ergo";Options
Section titled “Options”Pass directives as a raw string to bypass structured options.
| Option | Type | Default | Description |
|---|---|---|---|
directives | string | — | Raw directive string (overrides all below) |
public | boolean | false | Add public |
private | boolean | false | Add private |
noCache | boolean | false | Add no-cache |
noStore | boolean | false | Add no-store |
noTransform | boolean | false | Add no-transform |
mustRevalidate | boolean | false | Add must-revalidate |
proxyRevalidate | boolean | false | Add proxy-revalidate |
immutable | boolean | false | Add immutable |
maxAge | number | — | max-age in seconds |
sMaxAge | number | — | s-maxage in seconds |
staleWhileRevalidate | number | — | stale-while-revalidate in seconds |
staleIfError | number | — | stale-if-error in seconds |
Return Value
Section titled “Return Value”Always returns response headers:
{ response: { headers: [["Cache-Control", "private, no-cache"]] } }Error Responses
Section titled “Error Responses”None. This middleware always injects headers.
import { compose, cacheControl } from "@centralping/ergo";
// String shorthandconst pipeline = compose( cacheControl({ directives: "public, max-age=3600" }),);
// Structured optionsconst pipeline = compose( cacheControl({ private: true, maxAge: 0, mustRevalidate: true, }),);router.get("/static/:id", { cacheControl: { public: true, maxAge: 86400, immutable: true }, execute: (req, res, acc) => ({ response: { body: staticContent }, }),});RFC References
Section titled “RFC References”API Reference
Section titled “API Reference”See the auto-generated cacheControl API docs.