Skip to content

Responses & tags ​

Inertia\Response gets macros to tune the policy of a single response:

php
return Inertia::render('Post/Show', ['post' => $post])
    ->revalidate(3600)            // edge TTL for this response
    ->staleWhileRevalidate(86400)
    ->staleIfError(604800)
    ->tags(['posts', "post:{$post->id}"]);

->expire($seconds) sets the total lifetime instead of staleWhileRevalidate (stale-while-revalidate is expire - revalidate).

These macros override the route options for the current request only. tags() adds to the route's tags. On dynamic routes they are ignored.

Tags ​

Tags are sent in the provider's tag header (Cache-Tag, Surrogate-Key, xkey…) and recorded in the tag registry when one is enabled. Purging a tag purges both URLs of every page carrying it: the HTML and its page JSON.

Good tag design:

TagPurged when
postsany post changes (listings, archives, home widgets)
post:42post 42 changes (its page)
author:7author 7 changes (bio box on every post)

HasStaticTags uses [table, singular:id] by default (posts, post:42). Override staticTags() to change it.

What is cached ​

Only responses of isr and static routes are cached, and only when it is safe (Fail-safe cache policy):

ResponseCached?
200 HTML rendered with SSRyes, revalidate
200 page JSON (/__inertia/...)yes, revalidate
404yes, defaults.not_found_ttl (60s)
canonical 301 (query / trailing slash)yes, defaults.redirect_ttl (300s)
other redirectsonly with defaults.cache_redirects
5xx and any other statusnever
HTML rendered without SSR while SSR is enabled (SSR server down)like any page (never with ssr.required on)
requests with Authorization, preview mode, partial reloads, leaksnever

Released under the MIT License.