src/CacheSubscriber.php
public function onBefore(BeforeEvent $event)
    {
        $request = $event->getRequest();

        if (!$this->canCacheRequest($request)) {
            $this->cacheMiss($request);
            return;
        }

        if (!($response = $this->storage->fetch($request))) {
            $this->cacheMiss($request);
            return;
        }

        $response->setHeader('Age', Utils::getResponseAge($response));
        $valid = $this->validate($request, $response);

        // Validate that the response satisfies the request
        if ($valid) {
            $request->getConfig()->set('cache_lookup', 'HIT');
            $request->getConfig()->set('cache_hit', true);
            $event->intercept($response);
        } else {
            $this->cacheMiss($request);
        }
    }
public function onBefore(BeforeEvent $event)
    {
        $request = $event->getRequest();

        if (!$this->canCacheRequest($request)) {
            $this->cacheMiss($request);
            return;
        }

        if (!($response = $this->storage->fetch($request))) {
            $this->cacheMiss($request);
            return;
        }

        $response->setHeader('Age', Utils::getResponseAge($response));
        $valid = $this->validate($request, $response);

        // Validate that the response satisfies the request
        if ($valid) {
            $request->getConfig()->set('cache_lookup', 'HIT');
            $request->getConfig()->set('cache_hit', true);
            $event->intercept($response);
        } else {
            $this->cacheMiss($request);
        }
    }
public function onBefore ( BeforeEvent $ event ) { $ request = $ event -> getRequest ( ) ; if ( ! $ this -> canCacheRequest ( $ request ) ) { $ this -> cacheMiss ( $ request ) ; return ; } if ( ! ( $ response = $ this -> storage -> fetch ( $ request ) ) ) { $ this -> cacheMiss ( $ request ) ; return ; } $ response -> setHeader ( 'Age' , Utils :: getResponseAge ( $ response ) ) ; $ valid = $ this -> validate ( $ request , $ response ) ; // Validate that the response satisfies the request if ( $ valid ) { $ request -> getConfig ( ) -> set ( 'cache_lookup' , 'HIT' ) ; $ request -> getConfig ( ) -> set ( 'cache_hit' , true ) ; $ event -> intercept ( $ response ) ; } else { $ this -> cacheMiss ( $ request ) ; } }
Checks if a request can be cached, and if so, intercepts with a cached
response is available.

@param BeforeEvent $event
Checks if a request can be cached and if so intercepts with a cached response is available .