Esempio n. 1
0
 /**
  * Extract the cache HIT/MISS information from the X-Symfony-Cache header.
  *
  * For this header to be present, the HttpCache must be created with the
  * debug option set to true.
  *
  * @param CacheEvent $event
  */
 public function handleDebug(CacheEvent $event)
 {
     $response = $event->getResponse();
     if ($response->headers->has('X-Symfony-Cache')) {
         if (false !== strpos($response->headers->get('X-Symfony-Cache'), 'miss')) {
             $state = 'MISS';
         } elseif (false !== strpos($response->headers->get('X-Symfony-Cache'), 'fresh')) {
             $state = 'HIT';
         } else {
             $state = 'UNDETERMINED';
         }
         $response->headers->set('X-Cache', $state);
     }
 }
 /**
  * Remove the custom TTL header and restore s_maxage from the backup.
  *
  * @param CacheEvent $e
  */
 public function cleanResponse(CacheEvent $e)
 {
     $response = $e->getResponse();
     if (!$response->headers->has($this->ttlHeader) && !$response->headers->has(static::SMAXAGE_BACKUP)) {
         return;
     }
     if ($response->headers->has(static::SMAXAGE_BACKUP)) {
         $smaxage = $response->headers->get(static::SMAXAGE_BACKUP);
         if ('false' === $smaxage) {
             $response->headers->removeCacheControlDirective('s-maxage');
         } else {
             $response->headers->addCacheControlDirective('s-maxage', $smaxage);
         }
     }
     $response->headers->remove($this->ttlHeader);
     $response->headers->remove(static::SMAXAGE_BACKUP);
 }