Documentation

HttpCache extends HttpCache
in package

Manages HTTP cache objects in a Container.

Tags
author

Fabien Potencier fabien@symfony.com

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

$surrogateCacheStrategy

private mixed $surrogateCacheStrategy

Methods

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

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

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
throws
Exception
see
RFC2616

13.10

Return values
Response

isFreshEnough()

Checks whether the cache entry is "fresh enough" to satisfy the Request.

protected isFreshEnough(Request $request, Response $entry) : bool
Parameters
$request : Request
$entry : Response
Return values
bool

lock()

Locks a Request during the call to the backend.

protected lock(Request $request, Response $entry) : bool
Parameters
$request : Request
$entry : Response
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
throws
Exception
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

store()

Writes the Response to the cache.

protected store(Request $request, Response $response) : mixed
Parameters
$request : Request
$response : Response
Tags
throws
Exception
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
$request : Request
$entry : Response
$catch : bool = false

Whether to process exceptions

Return values
Response

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
$request : Request
$response : Response
Return values
mixed

waitForLock()

Waits for the store to release a locked entry.

private waitForLock(Request $request) : bool
Parameters
$request : Request
Return values
bool

Search results