Open Monograph Press  3.3.0
Guzzle\Plugin\Cache\CachePlugin Class Reference
Inheritance diagram for Guzzle\Plugin\Cache\CachePlugin:
Symfony\Component\EventDispatcher\EventSubscriberInterface

Public Member Functions

 __construct ($options=null)
 
 canResponseSatisfyFailedRequest (RequestInterface $request, Response $response)
 
 canResponseSatisfyRequest (RequestInterface $request, Response $response)
 
 onRequestBeforeSend (Event $event)
 
 onRequestError (Event $event)
 
 onRequestException (Event $event)
 
 onRequestSent (Event $event)
 
 purge ($url)
 

Static Public Member Functions

static getSubscribedEvents ()
 

Protected Member Functions

 addResponseHeaders (RequestInterface $request, Response $response)
 

Protected Attributes

 $autoPurge
 
 $canCache
 
 $revalidation
 
 $storage
 

Detailed Description

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

Definition at line 27 of file CachePlugin.php.

Constructor & Destructor Documentation

◆ __construct()

Guzzle\Plugin\Cache\CachePlugin::__construct (   $options = null)
Parameters
array | CacheAdapterInterface | CacheStorageInterface$optionsArray 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.
Exceptions
InvalidArgumentExceptionif no cache is provided and Doctrine cache is not installed

Definition at line 63 of file CachePlugin.php.

References Guzzle\Cache\CacheAdapterFactory\fromCache().

Member Function Documentation

◆ addResponseHeaders()

Guzzle\Plugin\Cache\CachePlugin::addResponseHeaders ( RequestInterface  $request,
Response  $response 
)
protected

◆ canResponseSatisfyFailedRequest()

Guzzle\Plugin\Cache\CachePlugin::canResponseSatisfyFailedRequest ( RequestInterface  $request,
Response  $response 
)

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

Parameters
RequestInterface$requestRequest to validate
Response$responseResponse to validate
Returns
bool

Definition at line 286 of file CachePlugin.php.

References Guzzle\Http\Message\Response\getAge(), Guzzle\Http\Message\AbstractMessage\getHeader(), and Guzzle\Http\Message\Response\getMaxAge().

Referenced by Guzzle\Plugin\Cache\CachePlugin\canResponseSatisfyRequest(), Guzzle\Plugin\Cache\CachePlugin\onRequestError(), and Guzzle\Plugin\Cache\CachePlugin\onRequestException().

◆ canResponseSatisfyRequest()

Guzzle\Plugin\Cache\CachePlugin::canResponseSatisfyRequest ( RequestInterface  $request,
Response  $response 
)

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

Parameters
RequestInterface$requestRequest to validate
Response$responseResponse to validate
Returns
bool

Definition at line 240 of file CachePlugin.php.

References Guzzle\Http\Message\Response\calculateAge(), Guzzle\Plugin\Cache\CachePlugin\canResponseSatisfyFailedRequest(), Guzzle\Http\Message\Response\getFreshness(), Guzzle\Http\Message\AbstractMessage\getHeader(), and Guzzle\Http\Message\Response\isFresh().

Referenced by Guzzle\Plugin\Cache\CachePlugin\onRequestBeforeSend().

◆ getSubscribedEvents()

static Guzzle\Plugin\Cache\CachePlugin::getSubscribedEvents ( )
static

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

Implements Symfony\Component\EventDispatcher\EventSubscriberInterface.

Definition at line 100 of file CachePlugin.php.

Referenced by Guzzle\Tests\Plugin\Cache\CachePluginTest\testAddsCallbackCollaborators(), and Guzzle\Tests\Plugin\Cache\CachePluginTest\testAddsDefaultCollaborators().

◆ onRequestBeforeSend()

Guzzle\Plugin\Cache\CachePlugin::onRequestBeforeSend ( Event  $event)

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

Parameters
Event$event

Definition at line 115 of file CachePlugin.php.

References Guzzle\Plugin\Cache\CachePlugin\canResponseSatisfyRequest(), Guzzle\Plugin\Cache\CachePlugin\purge(), and Guzzle\Common\Version\VERSION.

◆ onRequestError()

Guzzle\Plugin\Cache\CachePlugin::onRequestError ( Event  $event)

◆ onRequestException()

Guzzle\Plugin\Cache\CachePlugin::onRequestException ( Event  $event)

If possible, set a cache response on a cURL exception

Parameters
Event$event
Returns
null

Definition at line 209 of file CachePlugin.php.

References Guzzle\Plugin\Cache\CachePlugin\addResponseHeaders(), Guzzle\Plugin\Cache\CachePlugin\canResponseSatisfyFailedRequest(), and Symfony\Component\EventDispatcher\Event\stopPropagation().

◆ onRequestSent()

Guzzle\Plugin\Cache\CachePlugin::onRequestSent ( Event  $event)

If possible, store a response in cache after sending

Parameters
Event$event

Definition at line 159 of file CachePlugin.php.

References Guzzle\Plugin\Cache\CachePlugin\addResponseHeaders().

◆ purge()

Guzzle\Plugin\Cache\CachePlugin::purge (   $url)

Purge all cache entries for a given URL

Parameters
string$urlURL to purge

Definition at line 313 of file CachePlugin.php.

References Guzzle\Http\Message\RequestInterface\getUrl().

Referenced by Guzzle\Plugin\Cache\CachePlugin\onRequestBeforeSend().

Field Documentation

◆ $autoPurge

bool Guzzle\Plugin\Cache\CachePlugin::$autoPurge
protected

Definition at line 51 of file CachePlugin.php.

◆ $canCache

CanCacheStrategyInterface Guzzle\Plugin\Cache\CachePlugin::$canCache
protected

Object used to determine if a request can be cached

Definition at line 39 of file CachePlugin.php.

◆ $revalidation

RevalidationInterface Guzzle\Plugin\Cache\CachePlugin::$revalidation
protected

Cache revalidation strategy

Definition at line 33 of file CachePlugin.php.

◆ $storage

CacheStorageInterface Guzzle\Plugin\Cache\CachePlugin::$storage
protected

$cache Object used to cache responses

Definition at line 45 of file CachePlugin.php.


The documentation for this class was generated from the following file: