Letting the gateway keep a response
A route whose declaration allows it, with cache: true, can let the gateway keep a response for the
callers of one tenant for a while. Set the Frontline-Cache header on the response, as
\Pushery\FrontlineApi\Http\CachePermission writes it:
use Pushery\FrontlineApi\Http\CachePermission;
return response()->json(['data' => []])->header(
CachePermission::HEADER,
new CachePermission(maxAge: 60, staleIfError: 300, vary: ['Accept-Language'])->toHeader(),
);
maxAge is how long the response stays the same for every caller of the tenant, from 1 to 86,400
seconds; staleIfError how much longer the gateway may still answer with it while your application
fails, from 0 to 86,400; vary the request headers the response depends on, such as its language.
A value outside those ranges and an empty or malformed name are refused with an exception instead
of written. The header never names the tenant: the gateway keys what it keeps by the caller's tenant
itself.
The package keeps the header only where the gateway may act on it: on a GET or HEAD request to
a route that allows caching and is no stream, on a response with status 200, and as a permission the
gateway reads. From every other response it removes the header before the response leaves your
application. A gateway without its short-term store ignores the header.