Cache Configuration
The [cache] section controls PRISM's in-memory cache for rendered HTML. Caching avoids redundant renders and dramatically reduces response times for repeat requests.
TOML Example
[cache]
enabled = true
max_entries = 10000
max_memory_bytes = 268435456
default_ttl_secs = 3600
grace_period_secs = 300
strip_query_params = ["utm_*", "fbclid", "gclid", "msclkid", "_ga"]
error_ttl_secs = 30
skip_authenticated = true
synthesize_cache_control = true
ignore_origin_no_cache = false
honor_request_no_cache = false
[[cache.rules]]
pattern = "/blog/**"
ttl_secs = 86400
[[cache.rules]]
pattern = "/products/**"
ttl_secs = 7200
[[cache.rules]]
pattern = "/special-page"
ttl_secs = 60
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
enabled | Boolean | true | Enable or disable caching entirely |
max_entries | Integer | 10000 | Maximum number of cached pages |
max_memory_bytes | Integer | 268435456 (256 MiB) | Maximum memory for cached content |
default_ttl_secs | Integer | 3600 (1 hour) | Default time-to-live for cached entries |
grace_period_secs | Integer | 300 (5 minutes) | Serve stale content while revalidating in background |
stale_if_error_secs | Integer | 0 (disabled) | Serve a stored copy that expired up to this long ago when a fresh render cannot be had. See stale_if_error_secs below |
rules | Array of {pattern, ttl_secs, ignore_origin_no_cache} | [] | Path-specific TTL overrides using glob patterns. ignore_origin_no_cache is optional and overrides the global setting for matching URLs |
strip_query_params | Array of Strings | ["utm_*", "fbclid", "gclid", "msclkid", "_ga"] | Query parameters to strip from cache keys (supports globs) |
allowed_query_params | Array of Strings | unset | When set, only query parameters whose name matches are kept in cache keys and in the URL Chrome renders; all others are dropped (supports globs). An empty list keeps none |
error_ttl_secs | Integer | 30 | TTL for caching error responses (status >= 500). 0 = do not cache errors |
skip_authenticated | Boolean | true | Send requests with an Authorization header or any cookie to the origin instead of rendering them (render-all). In bot-only, an Authorization header (not a cookie) makes a bot request skip the cache |
invalidate_on_unsafe_methods | Boolean | true | Drop the cached copies of a URL when a POST, PUT, DELETE or PATCH to it succeeds. See invalidate_on_unsafe_methods below. |
synthesize_cache_control | Boolean or String | true | Cache-Control to add to rendered responses when the origin sent none: false (nothing), "public", "private", or true ("private" in bot-only mode, "public" in render-all mode). See synthesize_cache_control below. |
ignore_origin_no_cache | Boolean | false | Do not let the origin's no-cache, max-age=0, s-maxage=0, must-revalidate, Age or Date stop PRISM storing a render. See Origin caching headers below. |
honor_no_transform | Boolean | false | Stop rendering a response whose origin sent Cache-Control: no-transform, serving it unchanged instead |
vary | Array of Strings | [] | Request headers that fragment the cache key AND are forwarded to Chrome during render. See vary below. |
honor_request_no_cache | Boolean | false | Re-render instead of serving a stored response when the request carries Cache-Control: no-cache. See honor_request_no_cache below. |
Detailed Explanation
max_memory_bytes
The default is 256 MiB (268435456 bytes). When this limit is reached, the least recently used entries are evicted. Size your allocation based on average page size and expected unique URLs.
grace_period_secs
When a cached entry expires, PRISM can still serve the stale version for up to grace_period_secs while triggering a background re-render. This prevents cache stampedes and ensures visitors never wait for a cold render.
Serving stale has to be permitted, though. Since 1.4.0 an entry whose origin sent must-revalidate, proxy-revalidate or s-maxage is excluded: those forbid serving a stale response, and s-maxage carries proxy-revalidate semantics for shared caches (RFC 9111 §5.2.2.10). Such entries expire outright instead of entering the window — the freshness the origin granted is kept in full, and only the extension is withheld.
A background re-render that comes back uncacheable also removes the entry it was refreshing, rather than leaving the old copy to be served for the rest of the window.
stale_if_error_secs
When a crawler's request cannot be answered with a fresh result, PRISM can answer with the copy it still holds of that page, provided the copy expired no longer ago than stale_if_error_secs. A suggested value is 86400 (one day). The default, 0, turns this off and keeps the behaviour of earlier versions.
It applies when a request for a rendered page would otherwise get an error:
- the render failed (a timeout, a navigation error, a crash, a failed content check);
- the render was refused for capacity: no tab became free, the circuit breaker is open, or a rate limit was hit;
- the render completed, but the origin answered with a status of 500 or above.
The stored copy is the one under the same cache key: the same URL, device class and vary variant. It is served with the status it was stored with and marked STALE (see response headers). Each such response is counted in prism_cache_stale_if_error_total.
It never applies when the crawler is correctly given the origin's own response: a non-HTML document, a document that left the origin, or Cache-Control: no-transform with honor_no_transform on. Nor does it serve:
- a copy the origin forbade serving stale (
must-revalidate,proxy-revalidate,s-maxage), the same exclusion as forgrace_period_secs; - a stored error (status 500 or above);
- a copy that expired longer ago than the window.
The stored copy is left exactly as it is. A failed attempt does not renew its lifetime, and an origin 5xx is not stored over it, so the next request tries a fresh render again. grace_period_secs is separate: inside the grace window the copy is served while a background render refreshes it, and this setting only matters after that window has closed.
rules
A key in a rule other than pattern and ttl_secs is ignored, and PRISM warns at startup (and in prism validate) naming the key and the rule.
TTL rules are evaluated in order; the first matching glob pattern wins. If no rule matches, default_ttl_secs is used.
[[cache.rules]]
pattern = "/blog/**"
ttl_secs = 86400 # Blog posts: 24 hours
[[cache.rules]]
pattern = "/products/**"
ttl_secs = 7200 # Product pages: 2 hours
Place more specific patterns before broader ones, since the first match wins.
strip_query_params
Marketing and analytics query parameters are stripped from cache keys to avoid duplicate cache entries for the same page. Supports glob patterns (e.g., utm_* matches utm_source, utm_medium, utm_campaign, etc.).
allowed_query_params
Every distinct query string is a distinct cache entry and a distinct Chrome render. strip_query_params removes known tracking parameters, but an unknown parameter (?x=1, ?x=2, ...) still makes a new render, and such junk entries push real pages out of the cache.
Set allowed_query_params to the parameter names your pages really depend on. Unset (the default), nothing changes. Set, a parameter is kept in the cache key and in the URL Chrome navigates to only if its name matches the list; every other parameter is dropped, exactly as a stripped parameter is. strip_query_params still applies on top. An empty list ([]) keeps no query parameter. Globs work as in strip_query_params.
[cache]
# A shop: pagination, search and sorting change the page, nothing else does.
allowed_query_params = ["page", "q", "sort"]
With this, /shop?q=shoes&utm_source=x&session=9&page=2 is cached and rendered as /shop?page=2&q=shoes. Only the cache key and the render are affected: visitors are proxied to the origin with their full query string.
Query parameter order
After stripping, PRISM sorts the remaining parameters by name and then by value, and writes them out again in the standard form encoding. That one string is both the cache key and the URL Chrome requests from your origin, so /shop?b=2&a=1 and /shop?a=1&b=2 share one render and one entry. This happens on every rendered route, whether or not strip_query_params or allowed_query_params removed anything.
This is safe when the page depends on which parameters are present and what they hold, which is how most storefronts read a query string. It is not safe for a route where any of these matter:
- the order of the parameters, or the order of a repeated one (
?step=b&step=ais rendered as?step=a&step=b); - the exact bytes of the query string, as with a signed URL, where re-encoding (
%20becomes+) breaks the signature.
Keep such routes out of rendering with routes.exclude. An excluded route is proxied to the origin with the query string as the client sent it.
skip_authenticated
In render-all mode, requests carrying an Authorization header or any cookie are sent straight to the origin rather than rendered.
Chrome renders with no session, so the render has no cart, no account and no per-customer pricing. Keeping that result out of the cache is not enough on its own — it stops one shopper's page reaching another, but the shopper who asked still receives the anonymous render. So these requests bypass rendering entirely.
In bot-only mode a human is already bypassed for being human. There a bot request carrying an Authorization header skips the cache and request coalescing, so its render is neither served from nor stored in the cache. A Cookie header alone does not: the render is anonymous whatever cookies the client sent, so a bot request with a cookie is served from and stored in the cache like any other. Otherwise any client could force a fresh Chrome render of every request by adding a cookie.
An edge cache in front of PRISM needs its own rule: it may answer an authenticated request from a previously cached anonymous copy before PRISM ever sees it. Bypass edge caching for session cookies and Authorization.
invalidate_on_unsafe_methods
RFC 9111 §4.4 says a cache must drop what it holds for a URL when an unsafe method succeeds on it. PRISM follows that: when a request with a method other than GET, HEAD, OPTIONS or TRACE gets a response below 400 from the origin, every cached copy of that URL (all device and Vary variants) is dropped, and a render of it that is still running cannot publish its result.
Three limits apply:
- Only URLs PRISM would render are considered, that is, paths that match your
routes.includeand are not excluded byroutes.excludeor the built-in exclusions. APOSTto/api/**or/graphqldoes no cache work. - Nothing happens when there is nothing to drop.
- Each client address may cause at most 10 invalidations a minute (a burst of 10, refilled at one every 6 seconds). Over that, the request is still proxied as normal but the cache is left alone. A token is spent only when something is actually dropped.
Invalidation is local to the instance that saw the request; other replicas keep their copies until they expire or you purge them.
Set invalidate_on_unsafe_methods = false if your origin answers unsafe methods on page URLs with 2xx or 3xx without changing the page (for example a form that posts back to the page URL and redirects), or if you do not want clients to be able to empty the cache of a URL at all. Unsafe methods then never touch the cache, and a changed page is picked up when its entry expires or when you purge it through the admin API.
prism_cache_invalidations_total counts the URLs dropped and prism_cache_invalidations_refused_total counts the requests refused for being over budget.
synthesize_cache_control
When the origin does not include a Cache-Control header, PRISM adds one based on the configured TTL for that path. A Cache-Control the origin sends is never replaced.
| Value | Header added |
|---|---|
false | none |
"public" | public, max-age=<ttl>, s-maxage=<ttl> |
"private" | private, max-age=<ttl> |
true (default) | "private" in bot-only mode, "public" in render-all mode |
In bot-only mode one URL has two representations: crawlers get rendered HTML and visitors get your origin's own page. Only Vary: User-Agent separates them for a shared cache, and several CDNs ignore Vary. A CDN like that would store the crawler HTML and serve it to visitors, so the default does not invite shared caches to store it. In render-all mode every client gets the same rendered page, so public is safe. Set "public" in bot-only mode only when the CDN keys on the crawler class or on User-Agent and you have checked it. See CDN integration.
The lifetime in the header is the one PRISM stores the page under, so a stored error carries error_ttl_secs, not the route's TTL.
Origin caching headers
PRISM applies the caching headers of the page the origin sends to its own render cache:
| Origin sends | PRISM does |
|---|---|
no-store | Does not store the render. |
private | Does not store the render. |
Vary: * | Does not store the render. |
no-cache, max-age=0, s-maxage=0 | Does not store the render: PRISM cannot revalidate, so a stored copy could never be reused as the header requires. |
max-age=N or s-maxage=N (N > 0) | Stores it for the smaller of N and the configured TTL. |
must-revalidate, proxy-revalidate, s-maxage | Stores it but never serves it past its TTL, so the grace period does not apply. |
Age, Date | Counts the age the response already had against its lifetime. If that already exceeds the lifetime, the entry is stored stale and is never served fresh. |
Expires | Not read. |
no-cache or max-age=0 on index.html is standard advice for single-page apps, so that browsers pick up a new deploy. The same header makes every crawler request a fresh Chrome render, under your shared rate limits, with x-prism-cache: BYPASS as the only sign.
If the header is meant for browsers, set ignore_origin_no_cache = true. Then no-cache, max-age=0, s-maxage=0, must-revalidate, proxy-revalidate, Age and Date neither stop PRISM storing a render nor shorten how long it keeps it: your TTL rules decide. no-store, private, Vary: *, unreadable directives, a non-zero max-age and the status rules still apply. PRISM passes the origin's Cache-Control to the client unchanged either way, so browsers still revalidate.
A [[cache.rules]] entry may set the key too, in either direction. The first matching rule that sets it wins; otherwise the global value applies.
[cache]
ignore_origin_no_cache = false
[[cache.rules]]
pattern = "/app/**"
ttl_secs = 3600
ignore_origin_no_cache = true
To see refusals, read prism_cache_refusals_total{reason}, which counts every render PRISM did not keep, by reason. See metrics. When a successful (2xx) render is refused for no-cache, max-age=0 or an already-expired Age/Date, PRISM logs a warning naming the URL and the header, at most once every 10 minutes for the whole process. GET /explain shows the decision for a URL.
error_ttl_secs
Error responses (HTTP 500+) are cached for a shorter duration to avoid serving errors for extended periods while still providing some protection against repeated failing renders. Set to 0 to disable error caching entirely.
Since 1.4.0 this setting governs both ends: the Cache-Control PRISM sends downstream announces this lifetime too, so a CDN in front holds the error for as long as PRISM does and no longer. At 0 the response is announced no-store.
It does not apply to 401, 403, 407 or 429 — those are not stored at all unless the origin states a lifetime of its own. See status codes.
honor_no_transform
RFC 9111 §5.2.2.6 tells an intermediary not to transform a representation, and replacing a shell with rendered HTML is exactly that transformation. PRISM does not obey it by default, which is a deliberate departure worth explaining rather than hiding.
The directive exists to stop intermediaries the origin does not control —
a carrier proxy recompressing images, a transcoding gateway. PRISM is not one
of those: your own operator installs it, points it at your own site, and pays
for precisely the transformation it performs. Magento and several other stacks
also emit no-transform inside a boilerplate Cache-Control with no intention
about rendering at all.
The failure modes decide the default. Obeying automatically would mean an upgrade silently stops rendering for someone who bought PRISM to render, with the symptom appearing weeks later as "our SEO stopped working" and no obvious cause. Not obeying violates the letter of a directive in a way nobody observes. The second is the cheaper mistake.
It is a visible choice, not an omission: prism_no_transform_ignored_total
counts every response this affects, whatever the setting. If it is non-zero
and you care about the letter of the spec, turn this on.
With it on, such a response is fetched from the origin and served unchanged,
marked x-prism-fallback: no-transform. Note that no-transform says nothing
about storing — an origin that sends it with a lifetime still wants the
response cached, and PRISM still caches it.
vary
Use vary when the same path produces different rendered HTML depending on a request header — most commonly Accept-Language for multilingual SSR.
When configured, PRISM does two things for every header in the list:
- Fragments the cache key so that requests differing only in the header value are stored as separate cache entries.
- Forwards the header value to Chrome via
setExtraHTTPHeadersso the SSR can actually produce variant-specific HTML. Without this, vary would just multiply identical cache entries — so PRISM does both atomically.
[cache]
vary = ["accept-language"]
Header names are case-insensitive. Header values are used as raw strings — en-US and en-us are stored as different variants. Pre-normalize at your CDN or reverse proxy to avoid cache fragmentation; for example, collapse the browser default Accept-Language: en-US,en;q=0.9 to a single primary tag like en before forwarding to PRISM.
Default is empty ([]) — no vary, one cache entry per path. Leave it empty for single-language sites.
:::tip Why not vary on every header by default?
Each unique combination of vary values multiplies the cache footprint. Defaulting to vary on, say, Accept-Language would explode cache size for sites that don't actually serve language-varied HTML. Better to opt in.
:::
:::warning Vary headers and bot/CDN behavior
Bots typically don't send Accept-Language, so they all share one variant — fine for SEO. But CDN caches in front of PRISM must also vary on the same header, or they'll serve the wrong language. Configure Vary: Accept-Language on your CDN to match.
:::
Example Use Cases
E-commerce site with mixed content freshness
[cache]
enabled = true
max_entries = 50000
max_memory_bytes = 536870912 # 512 MiB
default_ttl_secs = 1800
[[cache.rules]]
pattern = "/products/**"
ttl_secs = 3600
[[cache.rules]]
pattern = "/categories/**"
ttl_secs = 7200
[[cache.rules]]
pattern = "/blog/**"
ttl_secs = 86400
Development / debugging with caching disabled
[cache]
enabled = false
Aggressive caching for mostly-static site
[cache]
enabled = true
max_entries = 100000
default_ttl_secs = 86400
grace_period_secs = 3600
error_ttl_secs = 60
honor_request_no_cache
RFC 9111 §5.2.1.4 says a request carrying Cache-Control: no-cache must not be
served a stored response without revalidation. PRISM ignores that header by
default, and the default is deliberate.
PRISM is a shared cache, usually reachable from the public internet, and a revalidation costs a full Chrome render. Honouring the header unconditionally means one header, repeated, forces unbounded renders — a cache-busting denial of service that needs no credentials and no volume.
Enable it only where the listener is reachable from callers you trust:
[cache]
honor_request_no_cache = true
Recognised on requests:
Cache-Control: no-cacheCache-Control: max-age=0Pragma: no-cache— the HTTP/1.0 spelling, still sent by several browsers on a forced reload
Directives are matched as whole comma-separated tokens, so no-cache-extension
does not trigger it.
When enabled, the fresh render is stored, not discarded. no-cache in a
request forbids reusing a stored response, not storing the new one, so the
re-render refreshes the entry that every later request sees. The revalidating
request is reported as X-Prism-Cache: MISS.
If you sit behind a CDN, strip Cache-Control and Pragma from client requests
at the edge before enabling this, or the protection is only as good as the CDN's
own behaviour.