NOTE: For Version 3 of the AWS SDK for PHP, please see the V3 User Guide and V3 API Reference.

# Class CachePlugin

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

  Guzzle\Plugin\Cache\CachePlugin implements Symfony\Component\EventDispatcher\EventSubscriberInterface

Namespace: Guzzle\Plugin\Cache
Located at Guzzle/Plugin/Cache/CachePlugin.php

## Methods summary

- `public` `__construct ( array|CacheAdapterInterface|CacheStorageInterface $options = null )`
- `public static` `getSubscribedEvents ( )`
- `public` `onRequestBeforeSend ( Guzzle\Common\Event $event )`

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

- `public` `onRequestSent ( Guzzle\Common\Event $event )`

  If possible, store a response in cache after sending

- `public` `onRequestError ( Guzzle\Common\Event $event )`

  If possible, return a cache response on an error

- `public` `onRequestException ( Guzzle\Common\Event $event )`

  If possible, set a cache response on a cURL exception

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

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

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

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

- `public` `purge ( string $url )`

  Purge all cache entries for a given URL

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

  Add the plugin's headers to a response

## Methods detail

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

#### Parameters

$options
  `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
# `public static`
`getSubscribedEvents( )`
# `public`
`onRequestBeforeSend( `Guzzle\Common\Event` $event )`

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

#### Parameters

$event
  ``Guzzle\Common\Event``
  $event

# `public`
`onRequestSent( `Guzzle\Common\Event` $event )`

If possible, store a response in cache after sending

#### Parameters

$event
  ``Guzzle\Common\Event``
  $event

# `public`
`onRequestError( `Guzzle\Common\Event` $event )`

If possible, return a cache response on an error

#### Parameters

$event
  ``Guzzle\Common\Event``
  $event

# `public null`
`onRequestException( `Guzzle\Common\Event` $event )`

If possible, set a cache response on a cURL exception

#### Parameters

$event
  ``Guzzle\Common\Event``
  $event

#### Returns

`null`
# `public boolean`
`canResponseSatisfyRequest( `Guzzle\Http\Message\RequestInterface` $request, `Guzzle\Http\Message\Response` $response )`

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

#### Parameters

$request
  ``Guzzle\Http\Message\RequestInterface``
  $request Request to validate
$response
  ``Guzzle\Http\Message\Response``
  $response Response to validate

#### Returns

`boolean`
# `public boolean`
`canResponseSatisfyFailedRequest( `Guzzle\Http\Message\RequestInterface` $request, `Guzzle\Http\Message\Response` $response )`

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

#### Parameters

$request
  ``Guzzle\Http\Message\RequestInterface``
  $request Request to validate
$response
  ``Guzzle\Http\Message\Response``
  $response Response to validate

#### Returns

`boolean`
# `public`
`purge( string $url )`

Purge all cache entries for a given URL

#### Parameters

$url
  `string`
  $url URL to purge

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

Add the plugin's headers to a response

#### Parameters

$request
  ``Guzzle\Http\Message\RequestInterface``
  $request Request
$response
  ``Guzzle\Http\Message\Response``
  $response Response to add headers to

### Magic methods summary

## Properties summary

`protected `Guzzle\Plugin\Cache\RevalidationInterface`` | $revalidation | # Cache revalidation strategy
`protected `Guzzle\Plugin\Cache\CanCacheStrategyInterface`` | $canCache | # Object used to determine if a request can be cached
`protected `Guzzle\Plugin\Cache\CacheStorageInterface`` | $storage | # $cache Object used to cache responses
`protected boolean` | $autoPurge | #