HttpCache
extends HttpCache
in package
Manages HTTP cache objects in a Container.
Tags
Table of Contents
- BODY_EVAL_BOUNDARY_LENGTH = 24
- $cacheDir : mixed
- $kernel : mixed
- $options : mixed
- $request : mixed
- $store : mixed
- $surrogate : mixed
- $surrogateCacheStrategy : mixed
- $traces : mixed
- __construct() : mixed
- Constructor.
- getKernel() : HttpKernelInterface
- Gets the Kernel instance.
- getLog() : string
- Returns a log message for the events of the last request processing.
- getRequest() : Request
- Gets the Request instance associated with the main request.
- getStore() : StoreInterface
- Gets the current store.
- getSurrogate() : SurrogateInterface
- Gets the Surrogate instance.
- getTraces() : array<string|int, mixed>
- Returns an array of events that took place during processing of the last request.
- handle() : Response
- Handles a Request to convert it to a Response.
- terminate() : mixed
- Terminates a request/response cycle.
- createStore() : StoreInterface
- createSurrogate() : SurrogateInterface
- fetch() : Response
- Unconditionally fetches a fresh response from the backend and stores it in the cache if is cacheable.
- forward() : Response
- Forwards the Request to the backend and returns the Response.
- getOptions() : array<string|int, mixed>
- Returns an array of options to customize the Cache configuration.
- invalidate() : Response
- Invalidates non-safe methods (like POST, PUT, and DELETE).
- isFreshEnough() : bool
- Checks whether the cache entry is "fresh enough" to satisfy the Request.
- lock() : bool
- Locks a Request during the call to the backend.
- lookup() : Response
- Lookups a Response from the cache for the given Request.
- pass() : Response
- Forwards the Request to the backend without storing the Response in the cache.
- processResponseBody() : mixed
- store() : mixed
- Writes the Response to the cache.
- validate() : Response
- Validates that a cache entry is fresh.
- addTraces() : mixed
- getTraceKey() : string
- Calculates the key we use in the "trace" array for a given request.
- isPrivateRequest() : bool
- Checks if the Request includes authorization or other sensitive information that should cause the Response to be considered private by default.
- mayServeStaleWhileRevalidate() : bool
- Checks whether the given (cached) response may be served as "stale" when a revalidation is currently in progress.
- record() : mixed
- Records that an event took place.
- restoreResponseBody() : mixed
- Restores the Response body.
- waitForLock() : bool
- Waits for the store to release a locked entry.
Constants
BODY_EVAL_BOUNDARY_LENGTH
public
mixed
BODY_EVAL_BOUNDARY_LENGTH
= 24
Properties
$cacheDir
protected
mixed
$cacheDir
$kernel
protected
mixed
$kernel
$options
private
mixed
$options
$request
private
mixed
$request
$store
private
mixed
$store
$surrogate
private
mixed
$surrogate
$surrogateCacheStrategy
private
mixed
$surrogateCacheStrategy
$traces
private
mixed
$traces
= []
Methods
__construct()
Constructor.
public
__construct(KernelInterface $kernel[, string|StoreInterface $cache = null ][, SurrogateInterface|null $surrogate = null ][, array<string|int, mixed>|null $options = null ]) : mixed
Parameters
- $kernel : KernelInterface
- $cache : string|StoreInterface = null
-
The cache directory (default used if null) or the storage instance
- $surrogate : SurrogateInterface|null = null
- $options : array<string|int, mixed>|null = null
Return values
mixed —getKernel()
Gets the Kernel instance.
public
getKernel() : HttpKernelInterface
Return values
HttpKernelInterface —getLog()
Returns a log message for the events of the last request processing.
public
getLog() : string
Return values
string —getRequest()
Gets the Request instance associated with the main request.
public
getRequest() : Request
Return values
Request —getStore()
Gets the current store.
public
getStore() : StoreInterface
Return values
StoreInterface —getSurrogate()
Gets the Surrogate instance.
public
getSurrogate() : SurrogateInterface
Tags
Return values
SurrogateInterface —getTraces()
Returns an array of events that took place during processing of the last request.
public
getTraces() : array<string|int, mixed>
Return values
array<string|int, mixed> —handle()
Handles a Request to convert it to a Response.
public
handle(Request $request[, int $type = HttpKernelInterface::MAIN_REQUEST ][, bool $catch = true ]) : Response
Parameters
- $request : Request
- $type : int = HttpKernelInterface::MAIN_REQUEST
-
The type of the request (one of HttpKernelInterface::MAIN_REQUEST or HttpKernelInterface::SUB_REQUEST)
- $catch : bool = true
-
Whether to catch exceptions or not
Return values
Response —terminate()
Terminates a request/response cycle.
public
terminate(Request $request, Response $response) : mixed
Parameters
Return values
mixed —createStore()
protected
createStore() : StoreInterface
Return values
StoreInterface —createSurrogate()
protected
createSurrogate() : SurrogateInterface
Return values
SurrogateInterface —fetch()
Unconditionally fetches a fresh response from the backend and stores it in the cache if is cacheable.
protected
fetch(Request $request[, bool $catch = false ]) : Response
Parameters
- $request : Request
- $catch : bool = false
-
Whether to process exceptions
Return values
Response —forward()
Forwards the Request to the backend and returns the Response.
protected
forward(Request $request[, bool $catch = false ][, Response|null $entry = null ]) : Response
Parameters
- $request : Request
- $catch : bool = false
-
Whether to catch exceptions or not
- $entry : Response|null = null
-
A Response instance (the stale entry if present, null otherwise)
Return values
Response —getOptions()
Returns an array of options to customize the Cache configuration.
protected
getOptions() : array<string|int, mixed>
Return values
array<string|int, mixed> —invalidate()
Invalidates non-safe methods (like POST, PUT, and DELETE).
protected
invalidate(Request $request[, bool $catch = false ]) : Response
Parameters
- $request : Request
- $catch : bool = false
-
Whether to process exceptions
Tags
Return values
Response —isFreshEnough()
Checks whether the cache entry is "fresh enough" to satisfy the Request.
protected
isFreshEnough(Request $request, Response $entry) : bool
Parameters
Return values
bool —lock()
Locks a Request during the call to the backend.
protected
lock(Request $request, Response $entry) : bool
Parameters
Return values
bool —true if the cache entry can be returned even if it is staled, false otherwise
lookup()
Lookups a Response from the cache for the given Request.
protected
lookup(Request $request[, bool $catch = false ]) : Response
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
- $catch : bool = false
-
Whether to process exceptions
Tags
Return values
Response —pass()
Forwards the Request to the backend without storing the Response in the cache.
protected
pass(Request $request[, bool $catch = false ]) : Response
Parameters
- $request : Request
- $catch : bool = false
-
Whether to process exceptions
Return values
Response —processResponseBody()
protected
processResponseBody(Request $request, Response $response) : mixed
Parameters
Return values
mixed —store()
Writes the Response to the cache.
protected
store(Request $request, Response $response) : mixed
Parameters
Tags
Return values
mixed —validate()
Validates that a cache entry is fresh.
protected
validate(Request $request, Response $entry[, bool $catch = false ]) : Response
The original request is used as a template for a conditional GET request with the backend.
Parameters
Return values
Response —addTraces()
private
addTraces(Response $response) : mixed
Parameters
- $response : Response
Return values
mixed —getTraceKey()
Calculates the key we use in the "trace" array for a given request.
private
getTraceKey(Request $request) : string
Parameters
- $request : Request
Return values
string —isPrivateRequest()
Checks if the Request includes authorization or other sensitive information that should cause the Response to be considered private by default.
private
isPrivateRequest(Request $request) : bool
Parameters
- $request : Request
Return values
bool —mayServeStaleWhileRevalidate()
Checks whether the given (cached) response may be served as "stale" when a revalidation is currently in progress.
private
mayServeStaleWhileRevalidate(Response $entry) : bool
Parameters
- $entry : Response
Return values
bool —record()
Records that an event took place.
private
record(Request $request, string $event) : mixed
Parameters
- $request : Request
- $event : string
Return values
mixed —restoreResponseBody()
Restores the Response body.
private
restoreResponseBody(Request $request, Response $response) : mixed
Parameters
Return values
mixed —waitForLock()
Waits for the store to release a locked entry.
private
waitForLock(Request $request) : bool
Parameters
- $request : Request