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
Esempio 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;
 }
Esempio n. 2
0
    /**
     * Lookups a Response from the cache for the given Request.
     *
     * {@inheritDoc}
     *
     * @param \Symfony\Component\HttpFoundation\Request $request
     * @param bool $catch
     * @return \Symfony\Component\HttpFoundation\Response
     */
    protected function lookup(Request $request, $catch = false)
    {
        $response = parent::lookup($request, $catch);

        if ($response->getAge() > 0
          && $response->headers->has('x-shopware-allow-nocache')
          && $request->cookies->has('nocache')) {
            $cacheTag = $response->headers->get('x-shopware-allow-nocache');
            $cacheTag = explode(', ', $cacheTag);
            foreach($cacheTag as $cacheTagValue) {
                if(strpos($request->cookies->get('nocache'), $cacheTagValue) !== false) {
                    $response = $this->fetch($request);
                    break;
                }
            }
        }

        if (!$this->options['debug']) {
            $response->headers->remove('x-shopware-allow-nocache');
            $response->headers->remove('x-shopware-cache-id');
        }

        return $response;
    }