示例#1
0
 /**
  * Lookups a Response from the cache for the given Request.
  *
  * When a matching cache entry is found and is fresh, it uses it as the
  * response without forwarding any request to the backend. When a matching
  * cache entry is found but is stale, it attempts to "validate" the entry with
  * the backend using conditional GET. When no matching cache entry is found,
  * it triggers "miss" processing.
  *
  * @param Symfony\Components\HttpKernel\Request $request A Request instance
  *
  * @return Symfony\Components\HttpKernel\Response A Response instance
  */
 protected function lookup(Request $request)
 {
     if ($this->options['allow_reload'] && $request->isNoCache()) {
         $this->record($request, 'reload');
         return $this->fetch($request);
     }
     try {
         $entry = $this->store->lookup($request);
     } catch (\Exception $e) {
         $this->record($request, 'lookup-failed');
         if ($this->options['debug']) {
             throw $e;
         }
         return $this->pass($request);
     }
     if (null === $entry) {
         $this->record($request, 'miss');
         return $this->fetch($request);
     }
     if (!$this->isFreshEnough($request, $entry)) {
         $this->record($request, 'stale');
         return $this->validate($request, $entry);
     }
     $this->record($request, 'fresh');
     $entry->headers->set('Age', $entry->getAge());
     return $entry;
 }