src/Guzzle/Plugin/Cache/CachePlugin.php
public function onRequestBeforeSend(Event $event)
    {
        $request = $event['request'];
        $request->addHeader('Via', sprintf('%s GuzzleCache/%s', $request->getProtocolVersion(), Version::VERSION));

        if (!$this->canCache->canCacheRequest($request)) {
            switch ($request->getMethod()) {
                case 'PURGE':
                    $this->purge($request);
                    $request->setResponse(new Response(200, array(), 'purged'));
                    break;
                case 'PUT':
                case 'POST':
                case 'DELETE':
                case 'PATCH':
                    if ($this->autoPurge) {
                        $this->purge($request);
                    }
            }
            return;
        }

        if ($response = $this->storage->fetch($request)) {
            $params = $request->getParams();
            $params['cache.lookup'] = true;
            $response->setHeader(
                'Age',
                time() - strtotime($response->getDate() ? : $response->getLastModified() ?: 'now')
            );
            // Validate that the response satisfies the request
            if ($this->canResponseSatisfyRequest($request, $response)) {
                if (!isset($params['cache.hit'])) {
                    $params['cache.hit'] = true;
                }
                $request->setResponse($response);
            }
        }
    }
public function onRequestBeforeSend(Event $event)
    {
        $request = $event['request'];
        $request->addHeader('Via', sprintf('%s GuzzleCache/%s', $request->getProtocolVersion(), Version::VERSION));

        if (!$this->canCache->canCacheRequest($request)) {
            switch ($request->getMethod()) {
                case 'PURGE':
                    $this->purge($request);
                    $request->setResponse(new Response(200, array(), 'purged'));
                    break;
                case 'PUT':
                case 'POST':
                case 'DELETE':
                case 'PATCH':
                    if ($this->autoPurge) {
                        $this->purge($request);
                    }
            }
            return;
        }

        if ($response = $this->storage->fetch($request)) {
            $params = $request->getParams();
            $params['cache.lookup'] = true;
            $response->setHeader(
                'Age',
                time() - strtotime($response->getDate() ? : $response->getLastModified() ?: 'now')
            );
            // Validate that the response satisfies the request
            if ($this->canResponseSatisfyRequest($request, $response)) {
                if (!isset($params['cache.hit'])) {
                    $params['cache.hit'] = true;
                }
                $request->setResponse($response);
            }
        }
    }
public function onRequestBeforeSend ( Event $ event ) { $ request = $ event [ 'request' ] ; $ request -> addHeader ( 'Via' , sprintf ( '%s GuzzleCache/%s' , $ request -> getProtocolVersion ( ) , Version :: VERSION ) ) ; if ( ! $ this -> canCache -> canCacheRequest ( $ request ) ) { switch ( $ request -> getMethod ( ) ) { case 'PURGE' : $ this -> purge ( $ request ) ; $ request -> setResponse ( new Response ( 200 , array ( ) , 'purged' ) ) ; break ; case 'PUT' : case 'POST' : case 'DELETE' : case 'PATCH' : if ( $ this -> autoPurge ) { $ this -> purge ( $ request ) ; } } return ; } if ( $ response = $ this -> storage -> fetch ( $ request ) ) { $ params = $ request -> getParams ( ) ; $ params [ 'cache.lookup' ] = true ; $ response -> setHeader ( 'Age' , time ( ) - strtotime ( $ response -> getDate ( ) ? : $ response -> getLastModified ( ) ? : 'now' ) ) ; // Validate that the response satisfies the request if ( $ this -> canResponseSatisfyRequest ( $ request , $ response ) ) { if ( ! isset ( $ params [ 'cache.hit' ] ) ) { $ params [ 'cache.hit' ] = true ; } $ request -> setResponse ( $ response ) ; } } }
Check if a response in cache will satisfy the request before sending

@param Event $event
Check if a response in cache will satisfy the request before sending