Class Guzzle\Plugin\Cache\CachePlugin

InheritanceGuzzle\Plugin\Cache\CachePlugin
ImplementsSymfony\Component\EventDispatcher\EventSubscriberInterface

Plugin to enable the caching of GET and HEAD requests. Caching can be done on all requests passing through this plugin or only after retrieving resources with cacheable response headers.

This is a simple implementation of RFC 2616 and should be considered a private transparent proxy cache, meaning authorization and private data can be cached.

It also implements RFC 5861's stale-if-error Cache-Control extension, allowing stale cache responses to be used when an error is encountered (such as a 500 Internal Server Error or DNS failure).

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() Guzzle\Plugin\Cache\CachePlugin
canResponseSatisfyFailedRequest() Check if a cache response satisfies a failed request's caching constraints Guzzle\Plugin\Cache\CachePlugin
canResponseSatisfyRequest() Check if a cache response satisfies a request's caching constraints Guzzle\Plugin\Cache\CachePlugin
getSubscribedEvents() Guzzle\Plugin\Cache\CachePlugin
onRequestBeforeSend() Check if a response in cache will satisfy the request before sending Guzzle\Plugin\Cache\CachePlugin
onRequestError() If possible, return a cache response on an error Guzzle\Plugin\Cache\CachePlugin
onRequestException() If possible, set a cache response on a cURL exception Guzzle\Plugin\Cache\CachePlugin
onRequestSent() If possible, store a response in cache after sending Guzzle\Plugin\Cache\CachePlugin
purge() Purge all cache entries for a given URL Guzzle\Plugin\Cache\CachePlugin

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
addResponseHeaders() Add the plugin's headers to a response Guzzle\Plugin\Cache\CachePlugin

Property Details

$autoPurge protected property
protected bool $autoPurge null
$canCache protected property

Object used to determine if a request can be cached

$revalidation protected property

Cache revalidation strategy

$storage protected property

Object used to cache responses

Method Details

__construct() public method

public void __construct ( $options null )
$options array|Guzzle\Cache\CacheAdapterInterface|Guzzle\Plugin\Cache\CacheStorageInterface

Array of options for the cache plugin,

cache adapter, or cache storage object.
- CacheStorageInterface storage:      Adapter used to cache responses
- RevalidationInterface revalidation: Cache revalidation strategy
- CanCacheInterface     can_cache:    Object used to determine if a request can be cached
- bool                  auto_purge    Set to true to automatically PURGE resources when non-idempotent
                                      requests are sent to a resource. Defaults to false.
throws Guzzle\Common\Exception\InvalidArgumentException

if no cache is provided and Doctrine cache is not installed

addResponseHeaders() protected method

Add the plugin's headers to a response

protected void addResponseHeaders ( Guzzle\Http\Message\RequestInterface $request, Guzzle\Http\Message\Response $response )
$request Guzzle\Http\Message\RequestInterface

Request

$response Guzzle\Http\Message\Response

Response to add headers to

canResponseSatisfyFailedRequest() public method

Check if a cache response satisfies a failed request's caching constraints

public bool canResponseSatisfyFailedRequest ( Guzzle\Http\Message\RequestInterface $request, Guzzle\Http\Message\Response $response )
$request Guzzle\Http\Message\RequestInterface

Request to validate

$response Guzzle\Http\Message\Response

Response to validate

canResponseSatisfyRequest() public method

Check if a cache response satisfies a request's caching constraints

public bool canResponseSatisfyRequest ( Guzzle\Http\Message\RequestInterface $request, Guzzle\Http\Message\Response $response )
$request Guzzle\Http\Message\RequestInterface

Request to validate

$response Guzzle\Http\Message\Response

Response to validate

getSubscribedEvents() public static method

public static void getSubscribedEvents ( )
onRequestBeforeSend() public method

Check if a response in cache will satisfy the request before sending

public void onRequestBeforeSend ( Guzzle\Common\Event $event )
$event Guzzle\Common\Event
onRequestError() public method

If possible, return a cache response on an error

public void onRequestError ( Guzzle\Common\Event $event )
$event Guzzle\Common\Event
onRequestException() public method

If possible, set a cache response on a cURL exception

public null onRequestException ( Guzzle\Common\Event $event )
$event Guzzle\Common\Event
onRequestSent() public method

If possible, store a response in cache after sending

public void onRequestSent ( Guzzle\Common\Event $event )
$event Guzzle\Common\Event
purge() public method

Purge all cache entries for a given URL

public void purge ( $url )
$url string

URL to purge