Ejemplo n.º 1
0
 /**
  * Tries to cache given response.
  *
  * @param Request $request
  * @param Response $response
  *
  * @return bool
  * @throws SecurityViolationException Tried to save cache entry wih unsafe path. Generally it should never occur
  *     unless invalid Request is passed.
  */
 public function cacheResponse(Request $request, Response $response)
 {
     $isCacheable = $this->isCacheable($request, $response);
     if ($isCacheable !== true) {
         if ($this->addStatusHeader) {
             $response->headers->set('X-Supercache', 'uncacheable,' . CacheManager::getUncachableReasonFromCode($isCacheable));
         }
         return false;
     }
     $status = $this->cachePush($request->getPathInfo(), $response->getContent(), $response->headers->get('Content-Type', 'application/octet-stream'));
     if ($this->addStatusHeader) {
         $response->headers->set('X-Supercache', 'MISS,' . (int) $status);
     }
     return (bool) $status;
 }