Store
in package
implements
StoreInterface
Store implements all the logic for storing cache metadata (Request and Response headers).
Tags
Interfaces, Classes, Traits and Enums
- StoreInterface
- Interface implemented by HTTP cache stores.
Table of Contents
- $root : mixed
- $keyCache : mixed
- $locks : mixed
- __construct() : mixed
- 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
- Restores a Response from the HTTP headers and body.
- save() : bool
- Save data for the given key.
Properties
$root
protected
mixed
$root
$keyCache
private
mixed
$keyCache
$locks
private
mixed
$locks
Methods
__construct()
public
__construct(string $root) : mixed
Parameters
- $root : string
Tags
Return values
mixed —cleanup()
Cleanups storage.
public
cleanup() : mixed
Return values
mixed —getPath()
public
getPath(mixed $key) : mixed
Parameters
- $key : mixed
Return values
mixed —invalidate()
Invalidates all cache entries that match the request.
public
invalidate(Request $request) : mixed
Parameters
- $request : Request
Tags
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
lookup()
Locates a cached Response for the Request provided.
public
lookup(Request $request) : Response|null
Parameters
- $request : Request
Return values
Response|null —A Response instance, or null if no cache entry was found
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
-
A URL
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
Tags
Return values
string —The key under which the response is stored
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 —A key for the given Request
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 $vary, array<string|int, mixed> $env1, array<string|int, mixed> $env2) : bool
Parameters
- $vary : string
-
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 $body = null ]) : Response
Parameters
- $headers : array<string|int, mixed>
- $body : string = null
Return values
Response —save()
Save data for the given key.
private
save(string $key, string $data) : bool
Parameters
- $key : string
- $data : string