src/CacheSubscriber.php
public static function attach(
        HasEmitterInterface $subject,
        array $options = []
    ) {
        if (!isset($options['storage'])) {
            $options['storage'] = new CacheStorage(new ArrayCache());
        }

        if (!isset($options['can_cache'])) {
            $options['can_cache'] = [
                'GuzzleHttp\Subscriber\Cache\Utils',
                'canCacheRequest',
            ];
        }

        $emitter = $subject->getEmitter();
        $cache = new self($options['storage'], $options['can_cache']);
        $emitter->attach($cache);

        if (!isset($options['validate']) || $options['validate'] === true) {
            $emitter->attach(new ValidationSubscriber(
                $options['storage'],
                $options['can_cache'])
            );
        }

        if (!isset($options['purge']) || $options['purge'] === true) {
            $emitter->attach(new PurgeSubscriber($options['storage']));
        }

        return ['subscriber' => $cache, 'storage' => $options['storage']];
    }
public static function attach(
        HasEmitterInterface $subject,
        array $options = []
    ) {
        if (!isset($options['storage'])) {
            $options['storage'] = new CacheStorage(new ArrayCache());
        }

        if (!isset($options['can_cache'])) {
            $options['can_cache'] = [
                'GuzzleHttp\Subscriber\Cache\Utils',
                'canCacheRequest',
            ];
        }

        $emitter = $subject->getEmitter();
        $cache = new self($options['storage'], $options['can_cache']);
        $emitter->attach($cache);

        if (!isset($options['validate']) || $options['validate'] === true) {
            $emitter->attach(new ValidationSubscriber(
                $options['storage'],
                $options['can_cache'])
            );
        }

        if (!isset($options['purge']) || $options['purge'] === true) {
            $emitter->attach(new PurgeSubscriber($options['storage']));
        }

        return ['subscriber' => $cache, 'storage' => $options['storage']];
    }
public static function attach ( HasEmitterInterface $ subject , array $ options = [ ] ) { if ( ! isset ( $ options [ 'storage' ] ) ) { $ options [ 'storage' ] = new CacheStorage ( new ArrayCache ( ) ) ; } if ( ! isset ( $ options [ 'can_cache' ] ) ) { $ options [ 'can_cache' ] = [ 'GuzzleHttp\Subscriber\Cache\Utils' , 'canCacheRequest' , ] ; } $ emitter = $ subject -> getEmitter ( ) ; $ cache = new self ( $ options [ 'storage' ] , $ options [ 'can_cache' ] ) ; $ emitter -> attach ( $ cache ) ; if ( ! isset ( $ options [ 'validate' ] ) || $ options [ 'validate' ] === true ) { $ emitter -> attach ( new ValidationSubscriber ( $ options [ 'storage' ] , $ options [ 'can_cache' ] ) ) ; } if ( ! isset ( $ options [ 'purge' ] ) || $ options [ 'purge' ] === true ) { $ emitter -> attach ( new PurgeSubscriber ( $ options [ 'storage' ] ) ) ; } return [ 'subscriber' => $ cache , 'storage' => $ options [ 'storage' ] ] ; }
Helper method used to easily attach a cache to a request or client.

This method accepts an array of options that are used to control the
caching behavior:

- storage: An optional GuzzleHttp\Subscriber\Cache\CacheStorageInterface.
If no value is not provided, an in-memory array cache will be used.
- validate: Boolean value that determines if cached response are ever
validated against the origin server. Defaults to true but can be
disabled by passing false.
- purge: Boolean value that determines if cached responses are purged
when non-idempotent requests are sent to their URI. Defaults to true
but can be disabled by passing false.
- can_cache: An optional callable used to determine if a request can be
cached. The callable accepts a RequestInterface and returns a boolean
value. If no value is provided, the default behavior is utilized.

@param HasEmitterInterface $subject Client or request to attach to,
@param array               $options Options used to control the cache.

@return array Returns an associative array containing a 'subscriber' key
that holds the created CacheSubscriber, and a 'storage'
key that contains the cache storage used by the subscriber.
Helper method used to easily attach a cache to a request or client .