HttpCache
class HttpCache extends HttpCache
Manages HTTP cache objects in a Container.
Properties
| protected | $cacheDir | ||
| protected | $kernel |
Methods
| __construct(HttpKernelInterface $kernel, string $cacheDir = null) | ||
| StoreInterface | getStore() Gets the current store. | from HttpCache |
| array | getTraces() Returns an array of events that took place during processing of the last request. | from HttpCache |
| string | getLog() Returns a log message for the events of the last request processing. | from HttpCache |
| Request | getRequest() Gets the Request instance associated with the master request. | from HttpCache |
| HttpKernelInterface | getKernel() Gets the Kernel instance. | from HttpCache |
| SurrogateInterface | getSurrogate() Gets the Surrogate instance. | from HttpCache |
| Response | handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true) Handles a Request to convert it to a Response. | from HttpCache |
| terminate(Request $request, Response $response) Terminates a request/response cycle. | from HttpCache | |
| Response | pass(Request $request, bool $catch = false) Forwards the Request to the backend without storing the Response in the cache. | from HttpCache |
| Response | invalidate(Request $request, bool $catch = false) Invalidates non-safe methods (like POST, PUT, and DELETE). | from HttpCache |
| Response | lookup(Request $request, bool $catch = false) Lookups a Response from the cache for the given Request. | from HttpCache |
| Response | validate(Request $request, Response $entry, bool $catch = false) Validates that a cache entry is fresh. | from HttpCache |
| Response | fetch(Request $request, bool $catch = false) Unconditionally fetches a fresh response from the backend and stores it in the cache if is cacheable. | from HttpCache |
| Response | forward(Request $request, bool $raw = 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. | from HttpCache |
| bool | lock(Request $request, Response $entry) Locks a Request during the call to the backend. | from HttpCache |
| store(Request $request, Response $response) Writes the Response to the cache. | from HttpCache | |
| processResponseBody(Request $request, Response $response) | from HttpCache | |
| array | getOptions() Returns an array of options to customize the Cache configuration. | |
| createSurrogate() | ||
| createStore() |
Details
__construct(HttpKernelInterface $kernel, string $cacheDir = null)
Parameters
| HttpKernelInterface | $kernel | |
| string | $cacheDir | The cache directory (default used if null) |
StoreInterface getStore()
Gets the current store.
Return Value
| StoreInterface | $store A StoreInterface instance |
array getTraces()
Returns an array of events that took place during processing of the last request.
Return Value
| array | An array of events |
string getLog()
Returns a log message for the events of the last request processing.
Return Value
| string | A log message |
Request getRequest()
Gets the Request instance associated with the master request.
Return Value
| Request | A Request instance |
HttpKernelInterface getKernel()
Gets the Kernel instance.
Return Value
| HttpKernelInterface | An HttpKernelInterface instance |
SurrogateInterface getSurrogate()
Gets the Surrogate instance.
Return Value
| SurrogateInterface | A Surrogate instance |
Exceptions
| LogicException |
Response handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true)
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.
Parameters
| 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 |
Return Value
| Response | A Response instance |
Exceptions
| Exception | When an Exception occurs during processing |
terminate(Request $request, Response $response)
Terminates a request/response cycle.
Should be called after sending the response and before shutting down the kernel.
Parameters
| Request | $request | |
| Response | $response |
protected Response pass(Request $request, bool $catch = false)
Forwards the Request to the backend without storing the Response in the cache.
Parameters
| Request | $request | A Request instance |
| bool | $catch | Whether to process exceptions |
Return Value
| Response | A Response instance |
protected Response invalidate(Request $request, bool $catch = false)
Invalidates non-safe methods (like POST, PUT, and DELETE).
Parameters
| Request | $request | A Request instance |
| bool | $catch | Whether to process exceptions |
Return Value
| Response | A Response instance |
Exceptions
| Exception |
See also
| RFC2616 | 13.10 |
protected Response lookup(Request $request, bool $catch = false)
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.
Parameters
| Request | $request | A Request instance |
| bool | $catch | Whether to process exceptions |
Return Value
| Response | A Response instance |
Exceptions
| Exception |
protected Response validate(Request $request, Response $entry, bool $catch = false)
Validates that a cache entry is fresh.
The original request is used as a template for a conditional GET request with the backend.
Parameters
| Request | $request | A Request instance |
| Response | $entry | A Response instance to validate |
| bool | $catch | Whether to process exceptions |
Return Value
| Response | A Response instance |
protected Response fetch(Request $request, bool $catch = false)
Unconditionally fetches a fresh response from the backend and stores it in the cache if is cacheable.
Parameters
| Request | $request | A Request instance |
| bool | $catch | Whether to process exceptions |
Return Value
| Response | A Response instance |
protected Response forward(Request $request, bool $raw = false, Response $entry = null)
Forwards the Request to the backend and returns the Response.
Parameters
| Request | $request | A Request instance |
| bool | $raw | Whether to catch exceptions or not |
| Response | $entry | A Response instance (the stale entry if present, null otherwise) |
Return Value
| Response | A Response instance |
protected bool isFreshEnough(Request $request, Response $entry)
Checks whether the cache entry is "fresh enough" to satisfy the Request.
Parameters
| Request | $request | |
| Response | $entry |
Return Value
| bool | true if the cache entry if fresh enough, false otherwise |
protected bool lock(Request $request, Response $entry)
Locks a Request during the call to the backend.
Parameters
| Request | $request | |
| Response | $entry |
Return Value
| bool | true if the cache entry can be returned even if it is staled, false otherwise |
protected store(Request $request, Response $response)
Writes the Response to the cache.
Parameters
| Request | $request | |
| Response | $response |
Exceptions
| Exception |
protected processResponseBody(Request $request, Response $response)
Parameters
| Request | $request | |
| Response | $response |
protected array getOptions()
Returns an array of options to customize the Cache configuration.
Return Value
| array | An array of options |
protected createSurrogate()
protected createStore()
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.html