/**
  * @param GetResponseEvent $event
  */
 public function readCacheData(GetResponseEvent $event)
 {
     if (array_key_exists($route = $event->getRequest()->attributes->get('_route'), $this->cachedRoutes)) {
         $cachedData = $this->responseCacher->readCache($event->getRequest(), $this->cachedRoutes[$route]);
         if (false !== $cachedData) {
             $event->setResponse(new Response($cachedData, 200, array('Content-Type' => 'application/json', 'X-Cache' => 'Hit', 'X-Cache-Key' => $event->getRequest()->attributes->get('cache_key'))));
             $event->getRequest()->attributes->set('cached_data', true);
         }
     }
 }
 /**
  * @param PostResponseEvent $event
  */
 public function cacheData(PostResponseEvent $event)
 {
     if ($event->getRequest()->query->get('no-cache', null)) {
         return;
     }
     if (array_key_exists($route = $event->getRequest()->attributes->get('_route'), $this->cachedRoutes)) {
         /** @var Response $response */
         $response = $event->getResponse();
         if ($response->getStatusCode() < 400) {
             if (!$event->getRequest()->attributes->has('cached_data')) {
                 $this->responseCacher->writeCache($event->getRequest(), $event->getResponse(), $this->cachedRoutes[$route]);
             }
         }
     }
 }