Skip to content

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 { cacheControl } from "@centralping/ergo";

Pass directives as a raw string to bypass structured options.

OptionTypeDefaultDescription
directivesstringRaw directive string (overrides all below)
publicbooleanfalseAdd public
privatebooleanfalseAdd private
noCachebooleanfalseAdd no-cache
noStorebooleanfalseAdd no-store
noTransformbooleanfalseAdd no-transform
mustRevalidatebooleanfalseAdd must-revalidate
proxyRevalidatebooleanfalseAdd proxy-revalidate
immutablebooleanfalseAdd immutable
maxAgenumbermax-age in seconds
sMaxAgenumbers-maxage in seconds
staleWhileRevalidatenumberstale-while-revalidate in seconds
staleIfErrornumberstale-if-error in seconds

Always returns response headers:

{ response: { headers: [["Cache-Control", "private, no-cache"]] } }

None. This middleware always injects headers.

import { compose, cacheControl } from "@centralping/ergo";
// String shorthand
const pipeline = compose(
cacheControl({ directives: "public, max-age=3600" }),
);
// Structured options
const pipeline = compose(
cacheControl({
private: true,
maxAge: 0,
mustRevalidate: true,
}),
);

See the auto-generated cacheControl API docs.