public function onKernelResponse(FilterResponseEvent $event)
    {
        // Only for Sub Requests
        $subRequest = $event->getRequest();
        if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
            return;
        }

        // Check if Annotation is present
        if (!$configuration = $subRequest->attributes->get('_andres_montanez_fragment_cache', false)) {
            return;
        }

        // If Key is present, save content for that key, expiration saved in seconds retreived in minutes
        if (($key = $subRequest->attributes->get('_andres_montanez_fragment_cache_key', false)) !== false) {
            if ($this->enabled) {
                $this->cache->set(
                    $key,
                    $event->getResponse()->getContent(),
                    $configuration->getExpiration() * 60
                );

                $fragment = '';
                if ($this->debug) {
                    $fragment .= '<!-- MISS - Begin Fragment Cache for KEY: ' . $key . ' -->';
                }

                $fragment .= $event->getResponse()->getContent();

                if ($this->debug) {
                    $fragment .= '<!-- End Fragment Cache for KEY: ' . $key . ' -->';
                }

                $event->getResponse()->setContent($fragment);

            } else if (!$this->enabled) {
                $fragment = '';
                if ($this->debug) {
                    $fragment .= '<!-- DISABLED - Begin Fragment Cache for KEY: ' . $key . ' -->';
                }

                $fragment .= $event->getResponse()->getContent();

                if ($this->debug) {
                    $fragment .= '<!-- End Fragment Cache for KEY: ' . $key . ' -->';
                }

                $event->getResponse()->setContent($fragment);
            }
        }

        return;
    }
public function onKernelResponse(FilterResponseEvent $event)
    {
        // Only for Sub Requests
        $subRequest = $event->getRequest();
        if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
            return;
        }

        // Check if Annotation is present
        if (!$configuration = $subRequest->attributes->get('_andres_montanez_fragment_cache', false)) {
            return;
        }

        // If Key is present, save content for that key, expiration saved in seconds retreived in minutes
        if (($key = $subRequest->attributes->get('_andres_montanez_fragment_cache_key', false)) !== false) {
            if ($this->enabled) {
                $this->cache->set(
                    $key,
                    $event->getResponse()->getContent(),
                    $configuration->getExpiration() * 60
                );

                $fragment = '';
                if ($this->debug) {
                    $fragment .= '<!-- MISS - Begin Fragment Cache for KEY: ' . $key . ' -->';
                }

                $fragment .= $event->getResponse()->getContent();

                if ($this->debug) {
                    $fragment .= '<!-- End Fragment Cache for KEY: ' . $key . ' -->';
                }

                $event->getResponse()->setContent($fragment);

            } else if (!$this->enabled) {
                $fragment = '';
                if ($this->debug) {
                    $fragment .= '<!-- DISABLED - Begin Fragment Cache for KEY: ' . $key . ' -->';
                }

                $fragment .= $event->getResponse()->getContent();

                if ($this->debug) {
                    $fragment .= '<!-- End Fragment Cache for KEY: ' . $key . ' -->';
                }

                $event->getResponse()->setContent($fragment);
            }
        }

        return;
    }
public function onKernelResponse ( FilterResponseEvent $ event ) { // Only for Sub Requests $ subRequest = $ event -> getRequest ( ) ; if ( $ event -> getRequestType ( ) == HttpKernelInterface :: MASTER_REQUEST ) { return ; } // Check if Annotation is present if ( ! $ configuration = $ subRequest -> attributes -> get ( '_andres_montanez_fragment_cache' , false ) ) { return ; } // If Key is present, save content for that key, expiration saved in seconds retreived in minutes if ( ( $ key = $ subRequest -> attributes -> get ( '_andres_montanez_fragment_cache_key' , false ) ) !== false ) { if ( $ this -> enabled ) { $ this -> cache -> set ( $ key , $ event -> getResponse ( ) -> getContent ( ) , $ configuration -> getExpiration ( ) * 60 ) ; $ fragment = '' ; if ( $ this -> debug ) { $ fragment .= '<!-- MISS - Begin Fragment Cache for KEY: ' . $ key . ' -->' ; } $ fragment .= $ event -> getResponse ( ) -> getContent ( ) ; if ( $ this -> debug ) { $ fragment .= '<!-- End Fragment Cache for KEY: ' . $ key . ' -->' ; } $ event -> getResponse ( ) -> setContent ( $ fragment ) ; } else if ( ! $ this -> enabled ) { $ fragment = '' ; if ( $ this -> debug ) { $ fragment .= '<!-- DISABLED - Begin Fragment Cache for KEY: ' . $ key . ' -->' ; } $ fragment .= $ event -> getResponse ( ) -> getContent ( ) ; if ( $ this -> debug ) { $ fragment .= '<!-- End Fragment Cache for KEY: ' . $ key . ' -->' ; } $ event -> getResponse ( ) -> setContent ( $ fragment ) ; } } return ; }
Listener for the Response call

@param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
@return void
Listener for the Response call