PHP Class Symfony\Component\HttpKernel\HttpCache\HttpCache

Author: Fabien Potencier ([email protected])
Inheritance: implements Symfony\Component\HttpKernel\HttpKernelInterface
Show file Open project: symfony/http-kernel Class Usage Examples

Public Methods

Method Description
__construct ( Symfony\Component\HttpKernel\HttpKernelInterface $kernel, Symfony\Component\HttpKernel\HttpCache\StoreInterface $store, Symfony\Component\HttpKernel\HttpCache\SurrogateInterface $surrogate = null, array $options = [] ) Constructor.
getKernel ( ) : Symfony\Component\HttpKernel\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 master request.
getStore ( ) : Symfony\Component\HttpKernel\HttpCache\StoreInterface Gets the current store.
getSurrogate ( ) : Symfony\Component\HttpKernel\HttpCache\SurrogateInterface Gets the Surrogate instance.
getTraces ( ) : array Returns an array of events that took place during processing of the last request.
handle ( Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true )
terminate ( Request $request, Response $response )

Protected Methods

Method Description
fetch ( Request $request, boolean $catch = false ) : Response Forwards the Request to the backend and determines whether the response should be stored.
forward ( Request $request, boolean $catch = false, Response $entry = null ) : Response Forwards the Request to the backend and returns the Response.
invalidate ( Request $request, boolean $catch = false ) : Response Invalidates non-safe methods (like POST, PUT, and DELETE).
isFreshEnough ( Request $request, Response $entry ) : boolean Checks whether the cache entry is "fresh enough" to satisfy the Request.
lock ( Request $request, Response $entry ) : boolean Locks a Request during the call to the backend.
lookup ( Request $request, boolean $catch = false ) : Response Lookups a Response from the cache for the given Request.
pass ( Request $request, boolean $catch = false ) : Response Forwards the Request to the backend without storing the Response in the cache.
processResponseBody ( Request $request, Response $response )
store ( Request $request, Response $response ) Writes the Response to the cache.
validate ( Request $request, Response $entry, boolean $catch = false ) : Response Validates that a cache entry is fresh.

Private Methods

Method Description
isPrivateRequest ( Request $request ) : boolean Checks if the Request includes authorization or other sensitive information that should cause the Response to be considered private by default.
record ( Request $request, string $event ) Records that an event took place.
restoreResponseBody ( Request $request, Response $response ) Restores the Response body.

Method Details

__construct() public method

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).
public __construct ( Symfony\Component\HttpKernel\HttpKernelInterface $kernel, Symfony\Component\HttpKernel\HttpCache\StoreInterface $store, Symfony\Component\HttpKernel\HttpCache\SurrogateInterface $surrogate = null, array $options = [] )
$kernel Symfony\Component\HttpKernel\HttpKernelInterface An HttpKernelInterface instance
$store Symfony\Component\HttpKernel\HttpCache\StoreInterface A Store instance
$surrogate Symfony\Component\HttpKernel\HttpCache\SurrogateInterface A SurrogateInterface instance
$options array An array of options

fetch() protected method

This methods is triggered when the cache missed or a reload is required.
protected fetch ( Request $request, boolean $catch = false ) : Response
$request Symfony\Component\HttpFoundation\Request A Request instance
$catch boolean whether to process exceptions
return Symfony\Component\HttpFoundation\Response A Response instance

forward() protected method

Forwards the Request to the backend and returns the Response.
protected forward ( Request $request, boolean $catch = false, Response $entry = null ) : Response
$request Symfony\Component\HttpFoundation\Request A Request instance
$catch boolean Whether to catch exceptions or not
$entry Symfony\Component\HttpFoundation\Response A Response instance (the stale entry if present, null otherwise)
return Symfony\Component\HttpFoundation\Response A Response instance

getKernel() public method

Gets the Kernel instance.
public getKernel ( ) : Symfony\Component\HttpKernel\HttpKernelInterface
return Symfony\Component\HttpKernel\HttpKernelInterface An HttpKernelInterface instance

getLog() public method

Returns a log message for the events of the last request processing.
public getLog ( ) : string
return string A log message

getRequest() public method

Gets the Request instance associated with the master request.
public getRequest ( ) : Request
return Symfony\Component\HttpFoundation\Request A Request instance

getStore() public method

Gets the current store.
public getStore ( ) : Symfony\Component\HttpKernel\HttpCache\StoreInterface
return Symfony\Component\HttpKernel\HttpCache\StoreInterface $store A StoreInterface instance

getSurrogate() public method

Gets the Surrogate instance.
public getSurrogate ( ) : Symfony\Component\HttpKernel\HttpCache\SurrogateInterface
return Symfony\Component\HttpKernel\HttpCache\SurrogateInterface A Surrogate instance

getTraces() public method

Returns an array of events that took place during processing of the last request.
public getTraces ( ) : array
return array An array of events

handle() public method

public handle ( Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true )
$request Symfony\Component\HttpFoundation\Request

invalidate() protected method

Invalidates non-safe methods (like POST, PUT, and DELETE).
See also: RFC2616 13.10
protected invalidate ( Request $request, boolean $catch = false ) : Response
$request Symfony\Component\HttpFoundation\Request A Request instance
$catch boolean Whether to process exceptions
return Symfony\Component\HttpFoundation\Response A Response instance

isFreshEnough() protected method

Checks whether the cache entry is "fresh enough" to satisfy the Request.
protected isFreshEnough ( Request $request, Response $entry ) : boolean
$request Symfony\Component\HttpFoundation\Request A Request instance
$entry Symfony\Component\HttpFoundation\Response A Response instance
return boolean true if the cache entry if fresh enough, false otherwise

lock() protected method

Locks a Request during the call to the backend.
protected lock ( Request $request, Response $entry ) : boolean
$request Symfony\Component\HttpFoundation\Request A Request instance
$entry Symfony\Component\HttpFoundation\Response A Response instance
return boolean true if the cache entry can be returned even if it is staled, false otherwise

lookup() protected method

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.
protected lookup ( Request $request, boolean $catch = false ) : Response
$request Symfony\Component\HttpFoundation\Request A Request instance
$catch boolean whether to process exceptions
return Symfony\Component\HttpFoundation\Response A Response instance

pass() protected method

Forwards the Request to the backend without storing the Response in the cache.
protected pass ( Request $request, boolean $catch = false ) : Response
$request Symfony\Component\HttpFoundation\Request A Request instance
$catch boolean Whether to process exceptions
return Symfony\Component\HttpFoundation\Response A Response instance

processResponseBody() protected method

protected processResponseBody ( Request $request, Response $response )
$request Symfony\Component\HttpFoundation\Request
$response Symfony\Component\HttpFoundation\Response

store() protected method

Writes the Response to the cache.
protected store ( Request $request, Response $response )
$request Symfony\Component\HttpFoundation\Request A Request instance
$response Symfony\Component\HttpFoundation\Response A Response instance

terminate() public method

public terminate ( Request $request, Response $response )
$request Symfony\Component\HttpFoundation\Request
$response Symfony\Component\HttpFoundation\Response

validate() protected method

The original request is used as a template for a conditional GET request with the backend.
protected validate ( Request $request, Response $entry, boolean $catch = false ) : Response
$request Symfony\Component\HttpFoundation\Request A Request instance
$entry Symfony\Component\HttpFoundation\Response A Response instance to validate
$catch boolean Whether to process exceptions
return Symfony\Component\HttpFoundation\Response A Response instance