\Guzzle\Plugin\CacheCachePlugin

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).

Summary

Methods
Properties
Constants
__construct()
getSubscribedEvents()
onRequestBeforeSend()
onRequestSent()
onRequestError()
onRequestException()
canResponseSatisfyRequest()
canResponseSatisfyFailedRequest()
purge()
No public properties found
No constants found
addResponseHeaders()
$revalidation
$canCache
$storage
$autoPurge
N/A
No private methods found
No private properties found
N/A

Properties

$autoPurge

$autoPurge : boolean

Type

boolean

Methods

__construct()

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

Parameters

array|\Guzzle\Cache\CacheAdapterInterface|\Guzzle\Plugin\Cache\CacheStorageInterface $options

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

getSubscribedEvents()

getSubscribedEvents() : array

Returns an array of event names this subscriber wants to listen to.

The array keys are event names and the value can be:

  • The method name to call (priority defaults to 0)
  • An array composed of the method name to call and the priority
  • An array of arrays composed of the method names to call and respective priorities, or 0 if unset

For instance:

  • array('eventName' => 'methodName')
  • array('eventName' => array('methodName', $priority))
  • array('eventName' => array(array('methodName1', $priority), array('methodName2')))

Returns

array —

The event names to listen to

onRequestBeforeSend()

onRequestBeforeSend(\Guzzle\Common\Event  $event) 

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

Parameters

\Guzzle\Common\Event $event

onRequestSent()

onRequestSent(\Guzzle\Common\Event  $event) 

If possible, store a response in cache after sending

Parameters

\Guzzle\Common\Event $event

onRequestError()

onRequestError(\Guzzle\Common\Event  $event) 

If possible, return a cache response on an error

Parameters

\Guzzle\Common\Event $event

onRequestException()

onRequestException(\Guzzle\Common\Event  $event) : null

If possible, set a cache response on a cURL exception

Parameters

\Guzzle\Common\Event $event

Returns

null

canResponseSatisfyRequest()

canResponseSatisfyRequest(\Guzzle\Http\Message\RequestInterface  $request, \Guzzle\Http\Message\Response  $response) : boolean

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

Parameters

\Guzzle\Http\Message\RequestInterface $request

Request to validate

\Guzzle\Http\Message\Response $response

Response to validate

Returns

boolean

canResponseSatisfyFailedRequest()

canResponseSatisfyFailedRequest(\Guzzle\Http\Message\RequestInterface  $request, \Guzzle\Http\Message\Response  $response) : boolean

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

Parameters

\Guzzle\Http\Message\RequestInterface $request

Request to validate

\Guzzle\Http\Message\Response $response

Response to validate

Returns

boolean

purge()

purge(string  $url) 

Purge all cache entries for a given URL

Parameters

string $url

URL to purge