Skip to main content

Module response_cache

Module response_cache 

Source
Expand description

The response cache, as the PHP package’s ResponseCache middleware and #[CacheResponse] attribute do it: a route opts in, its successful GET responses are kept in a Laravel cache store, and later requests are answered from the store with X-Response-Cache: hit. Entries are tagged, and flush drops every entry with any of the tags it is given.

The cached body is the latest version’s, from before the version changes run, so every version shares an entry. Entries are scoped to the API client (guest without one) unless the route marks them CacheResponse::shared.

A user signed in through Laravel’s own guards (the session guard, or a RequestGuard run by Authenticate::via) rather than as an API client has no client to scope an entry to, and the framework says only that someone is signed in, not who. Such a request skips the cache unless the route’s entries are shared: it is neither answered from the guest entry nor stored in it.

Structs§

CacheResponse
Route middleware that caches a route’s successful GET responses, as #[CacheResponse] does in PHP. Tags may name route parameters, such as orders:{order}.

Constants§

HEADER
The header that says whether the store answered the request.

Functions§

cache_key
The request’s response cache key and what it is made of, as the PHP package’s CacheKey makes them: the method (HEAD as GET), path, pinned version, client (guest without one) and query, with include and fields values in any order. The key is the same in both packages.
flush
Drops every cached response stored with any of the tags, such as orders and orders:5 after order 5 changes. Uses the default cache store, as the PHP package’s response_cache.store does when it is null; flush_in names another.
flush_in
flush in the named cache store.