Skip to main content

Module http_cache

Module http_cache 

Source
Expand description

Conditional responses and cache policy for admin and plugin routes.

This is response correctness, not a cache: nothing is stored server-side and nothing here is disabled in development. A validator that only appears in production is a validator nobody has tested, and the wrong policy on a generated file is caught precisely because it is live while you work.

Two shapes are offered, and which one fits is decided by whether the URL names the content:

  • A fingerprinted URL carries a digest of the bytes it serves, so a change produces a different URL. Those may be cached forever, and the answer never goes stale because the question changes.
  • A stable URL keeps its name across changes, so it may only be stored with revalidation. An ETag makes that revalidation cheap: unchanged bytes come back as a bodyless 304.

Constants§

IMMUTABLE
A fingerprinted URL’s policy: the digest in the path is the version, so the bytes behind it can never change.
PRIVATE_NO_STORE
An authenticated screen’s policy. Admin HTML is per-operator and often carries a request token, so no shared cache may hold it and no browser may keep it on disk for the next person at the machine.
REVALIDATE
A stable URL’s policy: store it, but ask before reusing it. Not no-store: the copy is kept, and the ETag turns the check into a 304.

Functions§

conditional
Answers a request for body with its validator, or a bodyless 304 when the client already holds it.
digest
A short content digest, used both as the URL’s version and as its ETag.
matches_etag
Whether the request already holds this exact entity, per If-None-Match.