src/Guzzle/Plugin/Cache/CachePlugin.php
public function canResponseSatisfyRequest(RequestInterface $request, Response $response)
    {
        $responseAge = $response->calculateAge();
        $reqc = $request->getHeader('Cache-Control');
        $resc = $response->getHeader('Cache-Control');

        // Check the request's max-age header against the age of the response
        if ($reqc && $reqc->hasDirective('max-age') &&
            $responseAge > $reqc->getDirective('max-age')) {
            return false;
        }

        // Check the response's max-age header
        if ($response->isFresh() === false) {
            $maxStale = $reqc ? $reqc->getDirective('max-stale') : null;
            if (null !== $maxStale) {
                if ($maxStale !== true && $response->getFreshness() < (-1 * $maxStale)) {
                    return false;
                }
            } elseif ($resc && $resc->hasDirective('max-age')
                && $responseAge > $resc->getDirective('max-age')
            ) {
                return false;
            }
        }

        if ($this->revalidation->shouldRevalidate($request, $response)) {
            try {
                return $this->revalidation->revalidate($request, $response);
            } catch (CurlException $e) {
                $request->getParams()->set('cache.hit', 'error');
                return $this->canResponseSatisfyFailedRequest($request, $response);
            }
        }

        return true;
    }
public function canResponseSatisfyRequest(RequestInterface $request, Response $response)
    {
        $responseAge = $response->calculateAge();
        $reqc = $request->getHeader('Cache-Control');
        $resc = $response->getHeader('Cache-Control');

        // Check the request's max-age header against the age of the response
        if ($reqc && $reqc->hasDirective('max-age') &&
            $responseAge > $reqc->getDirective('max-age')) {
            return false;
        }

        // Check the response's max-age header
        if ($response->isFresh() === false) {
            $maxStale = $reqc ? $reqc->getDirective('max-stale') : null;
            if (null !== $maxStale) {
                if ($maxStale !== true && $response->getFreshness() < (-1 * $maxStale)) {
                    return false;
                }
            } elseif ($resc && $resc->hasDirective('max-age')
                && $responseAge > $resc->getDirective('max-age')
            ) {
                return false;
            }
        }

        if ($this->revalidation->shouldRevalidate($request, $response)) {
            try {
                return $this->revalidation->revalidate($request, $response);
            } catch (CurlException $e) {
                $request->getParams()->set('cache.hit', 'error');
                return $this->canResponseSatisfyFailedRequest($request, $response);
            }
        }

        return true;
    }
public function canResponseSatisfyRequest ( RequestInterface $ request , Response $ response ) { $ responseAge = $ response -> calculateAge ( ) ; $ reqc = $ request -> getHeader ( 'Cache-Control' ) ; $ resc = $ response -> getHeader ( 'Cache-Control' ) ; // Check the request's max-age header against the age of the response if ( $ reqc && $ reqc -> hasDirective ( 'max-age' ) && $ responseAge > $ reqc -> getDirective ( 'max-age' ) ) { return false ; } // Check the response's max-age header if ( $ response -> isFresh ( ) === false ) { $ maxStale = $ reqc ? $ reqc -> getDirective ( 'max-stale' ) : null ; if ( null !== $ maxStale ) { if ( $ maxStale !== true && $ response -> getFreshness ( ) < ( - 1 * $ maxStale ) ) { return false ; } } elseif ( $ resc && $ resc -> hasDirective ( 'max-age' ) && $ responseAge > $ resc -> getDirective ( 'max-age' ) ) { return false ; } } if ( $ this -> revalidation -> shouldRevalidate ( $ request , $ response ) ) { try { return $ this -> revalidation -> revalidate ( $ request , $ response ) ; } catch ( CurlException $ e ) { $ request -> getParams ( ) -> set ( 'cache.hit' , 'error' ) ; return $ this -> canResponseSatisfyFailedRequest ( $ request , $ response ) ; } } return true ; }
Check if a cache response satisfies a request's caching constraints

@param RequestInterface $request  Request to validate
@param Response         $response Response to validate

@return bool
Check if a cache response satisfies a request s caching constraints