Documentation

Store
in package
implements StoreInterface

Store implements all the logic for storing cache metadata (Request and Response headers).

Tags
author

Fabien Potencier fabien@symfony.com

Interfaces, Classes and Traits

StoreInterface
Interface implemented by HTTP cache stores.

Table of Contents

$root  : mixed
$keyCache  : SplObjectStorage<Request, string>
$locks  : array<string, resource>
$options  : mixed
__construct()  : mixed
Constructor.
cleanup()  : mixed
Cleanups storage.
getPath()  : mixed
invalidate()  : mixed
Invalidates all cache entries that match the request.
isLocked()  : bool
Returns whether or not a lock exists.
lock()  : bool|string
Tries to lock the cache for a given Request, without blocking.
lookup()  : Response|null
Locates a cached Response for the Request provided.
purge()  : bool
Purges data for the given URL.
unlock()  : bool
Releases the lock for the given Request.
write()  : string
Writes a cache entry to the store for the given Request and Response.
generateCacheKey()  : string
Generates a cache key for the given Request.
generateContentDigest()  : string
Returns content digest for $response.
doPurge()  : bool
Purges data for the given URL.
getCacheKey()  : string
Returns a cache key for the given Request.
getMetadata()  : array<string|int, mixed>
Gets all data associated with the given key.
load()  : string|null
Loads data for the given key.
persistRequest()  : array<string|int, mixed>
Persists the Request HTTP headers.
persistResponse()  : array<string|int, mixed>
Persists the Response HTTP headers.
requestsMatch()  : bool
Determines whether two Request HTTP header sets are non-varying based on the vary response header value provided.
restoreResponse()  : Response|null
Restores a Response from the HTTP headers and body.
save()  : bool
Save data for the given key.

Properties

$locks

private array<string, resource> $locks = []

$options

private mixed $options

Methods

__construct()

Constructor.

public __construct(string $root[, array<string|int, mixed> $options = [] ]) : mixed

The available options are:

  • private_headers Set of response headers that should not be stored when a response is cached. (default: Set-Cookie)
Parameters
$root : string
$options : array<string|int, mixed> = []
Tags
throws
RuntimeException
Return values
mixed

cleanup()

Cleanups storage.

public cleanup() : mixed
Return values
mixed

getPath()

public getPath(string $key) : mixed
Parameters
$key : string
Return values
mixed

invalidate()

Invalidates all cache entries that match the request.

public invalidate(Request $request) : mixed
Parameters
$request : Request
Tags
throws
RuntimeException
Return values
mixed

isLocked()

Returns whether or not a lock exists.

public isLocked(Request $request) : bool
Parameters
$request : Request
Return values
bool

true if lock exists, false otherwise

lock()

Tries to lock the cache for a given Request, without blocking.

public lock(Request $request) : bool|string
Parameters
$request : Request
Return values
bool|string

true if the lock is acquired, the path to the current lock otherwise

purge()

Purges data for the given URL.

public purge(string $url) : bool

This method purges both the HTTP and the HTTPS version of the cache entry.

Parameters
$url : string
Return values
bool

true if the URL exists with either HTTP or HTTPS scheme and has been purged, false otherwise

unlock()

Releases the lock for the given Request.

public unlock(Request $request) : bool
Parameters
$request : Request
Return values
bool

False if the lock file does not exist or cannot be unlocked, true otherwise

write()

Writes a cache entry to the store for the given Request and Response.

public write(Request $request, Response $response) : string

Existing entries are read and any that match the response are removed. This method calls write with the new list of cache entries.

Parameters
$request : Request
$response : Response
Tags
throws
RuntimeException
Return values
string

generateCacheKey()

Generates a cache key for the given Request.

protected generateCacheKey(Request $request) : string

This method should return a key that must only depend on a normalized version of the request URI.

If the same URI can have more than one representation, based on some headers, use a Vary header to indicate them, and each representation will be stored independently under the same cache key.

Parameters
$request : Request
Return values
string

generateContentDigest()

Returns content digest for $response.

protected generateContentDigest(Response $response) : string
Parameters
$response : Response
Return values
string

doPurge()

Purges data for the given URL.

private doPurge(string $url) : bool
Parameters
$url : string
Return values
bool

getCacheKey()

Returns a cache key for the given Request.

private getCacheKey(Request $request) : string
Parameters
$request : Request
Return values
string

getMetadata()

Gets all data associated with the given key.

private getMetadata(string $key) : array<string|int, mixed>

Use this method only if you know what you are doing.

Parameters
$key : string
Return values
array<string|int, mixed>

load()

Loads data for the given key.

private load(string $key) : string|null
Parameters
$key : string
Return values
string|null

persistRequest()

Persists the Request HTTP headers.

private persistRequest(Request $request) : array<string|int, mixed>
Parameters
$request : Request
Return values
array<string|int, mixed>

persistResponse()

Persists the Response HTTP headers.

private persistResponse(Response $response) : array<string|int, mixed>
Parameters
$response : Response
Return values
array<string|int, mixed>

requestsMatch()

Determines whether two Request HTTP header sets are non-varying based on the vary response header value provided.

private requestsMatch(string|null $vary, array<string|int, mixed> $env1, array<string|int, mixed> $env2) : bool
Parameters
$vary : string|null

A Response vary header

$env1 : array<string|int, mixed>

A Request HTTP header array

$env2 : array<string|int, mixed>

A Request HTTP header array

Return values
bool

restoreResponse()

Restores a Response from the HTTP headers and body.

private restoreResponse(array<string|int, mixed> $headers[, string|null $path = null ]) : Response|null
Parameters
$headers : array<string|int, mixed>
$path : string|null = null
Return values
Response|null

save()

Save data for the given key.

private save(string $key, string $data[, bool $overwrite = true ]) : bool
Parameters
$key : string
$data : string
$overwrite : bool = true
Return values
bool

Search results