class HttpCache implements HttpKernelInterface, TerminableInterface
Cache provides HTTP caching.
__construct(HttpKernelInterface $kernel, StoreInterface $store, SurrogateInterface $surrogate = null, array $options = array()) Constructor. | ||
StoreInterface | getStore() Gets the current store. | |
array | getTraces() Returns an array of events that took place during processing of the last request. | |
string | getLog() Returns a log message for the events of the last request processing. | |
Request | getRequest() Gets the Request instance associated with the master request. | |
HttpKernelInterface | getKernel() Gets the Kernel instance. | |
SurrogateInterface | getSurrogate() Gets the Surrogate instance. | |
Response | handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true) Handles a Request to convert it to a Response. | |
terminate(Request $request, Response $response) Terminates a request/response cycle. | ||
Response | pass(Request $request, bool $catch = false) Forwards the Request to the backend without storing the Response in the cache. | |
Response | invalidate(Request $request, bool $catch = false) Invalidates non-safe methods (like POST, PUT, and DELETE). | |
Response | lookup(Request $request, bool $catch = false) Lookups a Response from the cache for the given Request. | |
Response | validate(Request $request, Response $entry, bool $catch = false) Validates that a cache entry is fresh. | |
Response | fetch(Request $request, bool $catch = false) Unconditionally fetches a fresh response from the backend and stores it in the cache if is cacheable. | |
Response | forward(Request $request, bool $catch = false, Response $entry = null) Forwards the Request to the backend and returns the Response. | |
bool | isFreshEnough(Request $request, Response $entry) Checks whether the cache entry is "fresh enough" to satisfy the Request. | |
bool | lock(Request $request, Response $entry) Locks a Request during the call to the backend. | |
store(Request $request, Response $response) Writes the Response to the cache. | ||
processResponseBody(Request $request, Response $response) |
Constructor.
The available options are:
debug: If true, the traces are added as a HTTP header to ease debugging
default_ttl The number of seconds that a cache entry should be considered fresh when no explicit freshness information is provided in a response. Explicit Cache-Control or Expires headers override this value. (default: 0)
private_headers Set of request headers that trigger "private" cache-control behavior on responses that don't explicitly state whether the response is public or private via a Cache-Control directive. (default: Authorization and Cookie)
allow_reload Specifies whether the client can force a cache reload by including a Cache-Control "no-cache" directive in the request. Set it to true
for compliance with RFC 2616. (default: false)
allow_revalidate Specifies whether the client can force a cache revalidate by including a Cache-Control "max-age=0" directive in the request. Set it to true
for compliance with RFC 2616. (default: false)
stale_while_revalidate Specifies the default number of seconds (the granularity is the second as the Response TTL precision is a second) during which the cache can immediately return a stale response while it revalidates it in the background (default: 2). This setting is overridden by the stale-while-revalidate HTTP Cache-Control extension (see RFC 5861).
stale_if_error Specifies the default number of seconds (the granularity is the second) during which the cache can serve a stale response when an error is encountered (default: 60). This setting is overridden by the stale-if-error HTTP Cache-Control extension (see RFC 5861).
HttpKernelInterface | $kernel | |
StoreInterface | $store | |
SurrogateInterface | $surrogate | |
array | $options |
Gets the current store.
StoreInterface | $store A StoreInterface instance |
Returns an array of events that took place during processing of the last request.
array | An array of events |
Returns a log message for the events of the last request processing.
string | A log message |
Gets the Request instance associated with the master request.
Request | A Request instance |
Gets the Kernel instance.
HttpKernelInterface | An HttpKernelInterface instance |
Gets the Surrogate instance.
SurrogateInterface | A Surrogate instance |
LogicException |
Handles a Request to convert it to a Response.
When $catch is true, the implementation must catch all exceptions and do its best to convert them to a Response instance.
Request | $request | A Request instance |
int | $type | The type of the request (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST) |
bool | $catch | Whether to catch exceptions or not |
Response | A Response instance |
Exception | When an Exception occurs during processing |
Terminates a request/response cycle.
Should be called after sending the response and before shutting down the kernel.
Request | $request | |
Response | $response |
Forwards the Request to the backend without storing the Response in the cache.
Request | $request | A Request instance |
bool | $catch | Whether to process exceptions |
Response | A Response instance |
Invalidates non-safe methods (like POST, PUT, and DELETE).
Request | $request | A Request instance |
bool | $catch | Whether to process exceptions |
Response | A Response instance |
Exception |
RFC2616 | 13.10 |
Lookups a Response from the cache for the given Request.
When a matching cache entry is found and is fresh, it uses it as the response without forwarding any request to the backend. When a matching cache entry is found but is stale, it attempts to "validate" the entry with the backend using conditional GET. When no matching cache entry is found, it triggers "miss" processing.
Request | $request | A Request instance |
bool | $catch | Whether to process exceptions |
Response | A Response instance |
Exception |
Validates that a cache entry is fresh.
The original request is used as a template for a conditional GET request with the backend.
Request | $request | A Request instance |
Response | $entry | A Response instance to validate |
bool | $catch | Whether to process exceptions |
Response | A Response instance |
Unconditionally fetches a fresh response from the backend and stores it in the cache if is cacheable.
Request | $request | A Request instance |
bool | $catch | Whether to process exceptions |
Response | A Response instance |
Forwards the Request to the backend and returns the Response.
All backend requests (cache passes, fetches, cache validations) run through this method.
Request | $request | A Request instance |
bool | $catch | Whether to catch exceptions or not |
Response | $entry | A Response instance (the stale entry if present, null otherwise) |
Response | A Response instance |
Checks whether the cache entry is "fresh enough" to satisfy the Request.
Request | $request | |
Response | $entry |
bool | true if the cache entry if fresh enough, false otherwise |
Locks a Request during the call to the backend.
Request | $request | |
Response | $entry |
bool | true if the cache entry can be returned even if it is staled, false otherwise |
Writes the Response to the cache.
Request | $request | |
Response | $response |
Exception |
Request | $request | |
Response | $response |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/HttpKernel/HttpCache/HttpCache.html