Symfony\Component\HttpKernel\HttpCache\HttpCache::lookup PHP Method

lookup() protected method

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.
protected lookup ( Request $request, boolean $catch = false ) : Response
$request Symfony\Component\HttpFoundation\Request A Request instance
$catch boolean whether to process exceptions
return Symfony\Component\HttpFoundation\Response A Response instance
    protected function lookup(Request $request, $catch = false)
    {
        // if allow_reload and no-cache Cache-Control, allow a cache reload
        if ($this->options['allow_reload'] && $request->isNoCache()) {
            $this->record($request, 'reload');
            return $this->fetch($request, $catch);
        }
        try {
            $entry = $this->store->lookup($request);
        } catch (\Exception $e) {
            $this->record($request, 'lookup-failed');
            if ($this->options['debug']) {
                throw $e;
            }
            return $this->pass($request, $catch);
        }
        if (null === $entry) {
            $this->record($request, 'miss');
            return $this->fetch($request, $catch);
        }
        if (!$this->isFreshEnough($request, $entry)) {
            $this->record($request, 'stale');
            return $this->validate($request, $entry, $catch);
        }
        $this->record($request, 'fresh');
        $entry->headers->set('Age', $entry->getAge());
        return $entry;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Lookups a Response from the cache for the given Request.
  *
  * {@inheritDoc}
  *
  * @param  Request  $request
  * @param  bool     $catch
  * @return Response
  */
 protected function lookup(Request $request, $catch = false)
 {
     $response = parent::lookup($request, $catch);
     // If Response is not fresh age > 0 AND contains a mathing no cache tag
     if ($response->getAge() > 0 && $this->containsNoCacheTag($request, $response)) {
         $response = $this->fetch($request);
     }
     if (!$this->options['debug']) {
         // Hide headers from client
         $response->headers->remove('x-shopware-allow-nocache');
         $response->headers->remove('x-shopware-cache-id');
     }
     return $response;
 }
All Usage Examples Of Symfony\Component\HttpKernel\HttpCache\HttpCache::lookup