示例#1
0
 /**
  * Sets the shopware cache headers
  */
 public function setCacheHeaders()
 {
     $controllerName = $this->buildControllerName($this->request);
     $cacheControllers = $this->getCacheControllers();
     if (!isset($cacheControllers[$controllerName])) {
         return false;
     }
     if (strpos($this->request->getPathInfo(), '/widgets/index/refreshStatistic') !== false) {
         return false;
     }
     if (strpos($this->request->getPathInfo(), '/captcha/index/rand/') !== false) {
         return false;
     }
     $allowNoCache = $this->getNoCacheTagsForController($controllerName);
     $noCacheCookies = $this->getNoCacheTagsFromCookie($this->request);
     $hasMatchingNoCacheCookie = $this->hasArrayIntersection($allowNoCache, $noCacheCookies);
     if ($this->response->isRedirect()) {
         $this->response->setHeader('Cache-Control', 'private, no-cache');
         return false;
     }
     if ($hasMatchingNoCacheCookie) {
         $this->response->setHeader('Cache-Control', 'private, no-cache');
         return false;
     }
     $allowNoCacheControllers = $this->getAllowNoCacheControllers();
     if (isset($allowNoCacheControllers[$controllerName]) && $this->request->getQuery('nocache') !== null) {
         $this->response->setHeader('Cache-Control', 'private, no-cache');
         return false;
     }
     // Don't cache when using admin session
     if (Shopware()->Session()->Admin) {
         return false;
     }
     // Don't cache filled basket or wishlist
     if ($controllerName == 'widgets/checkout' && (!empty(Shopware()->Session()->sBasketQuantity) || !empty(Shopware()->Session()->sNotesQuantity))) {
         $this->response->setHeader('Cache-Control', 'private, no-cache');
         return false;
     }
     $cacheTime = (int) $cacheControllers[$controllerName];
     $this->request->setParam('__cache', $cacheTime);
     $this->response->setHeader('Cache-Control', 'public, max-age=' . $cacheTime . ', s-maxage=' . $cacheTime);
     if (!empty($allowNoCache)) {
         $this->response->setHeader('x-shopware-allow-nocache', implode(', ', $allowNoCache));
     }
     $cacheIds = $this->getCacheIdsFromController($this->action);
     $this->setCacheIdHeader($cacheIds);
     return true;
 }
示例#2
0
 /**
  * Sets the shopware cache headers
  */
 public function setCacheHeaders()
 {
     $controllerName = strtolower($this->request->getModuleName()) . '/' . strtolower($this->request->getControllerName());
     $cacheControllers = $this->getCacheControllers();
     if (!isset($cacheControllers[$controllerName])) {
         return false;
     }
     if (strpos($this->request->getPathInfo(), '/widgets/index/refreshStatistic') !== false) {
         return false;
     }
     if (strpos($this->request->getPathInfo(), '/captcha/index/rand/') !== false) {
         return false;
     }
     $allowNoCache = $this->getNoCacheTagsForController($controllerName);
     $noCacheCookies = $this->getNoCacheTagsFromCookie($this->request);
     $hasMatchingNoCacheCookie = $this->hasArrayIntersection($allowNoCache, $noCacheCookies);
     // Enable esi tag output
     $this->registerEsiRenderer();
     if ($this->response->isRedirect()) {
         $this->response->setHeader('Cache-Control', 'private, no-cache');
         return false;
     }
     if ($hasMatchingNoCacheCookie) {
         $this->response->setHeader('Cache-Control', 'private, no-cache');
         return false;
     }
     $allowNoCacheControllers = $this->getAllowNoCacheControllers();
     if (isset($allowNoCacheControllers[$controllerName]) && $this->request->getQuery('nocache') !== null) {
         $this->response->setHeader('Cache-Control', 'private, no-cache');
         return false;
     }
     // NEVER cache a filled mini-basket
     if ($controllerName == 'widgets/checkout' && !empty(Shopware()->Session()->sBasketQuantity)) {
         $this->response->setHeader('Cache-Control', 'private, no-cache');
         return false;
     }
     $cacheTime = (int) $cacheControllers[$controllerName];
     $this->request->setParam('__cache', $cacheTime);
     $this->response->setHeader('Cache-Control', 'public, max-age=' . $cacheTime . ', s-maxage=' . $cacheTime, true);
     if (!empty($allowNoCache)) {
         $this->response->setHeader('x-shopware-allow-nocache', implode(', ', $allowNoCache));
     }
     return true;
 }
示例#3
0
    /**
     * Sets the shopware cache headers
     */
    public function setCacheHeaders()
    {
        $controllerName = $this->request->getModuleName() . '/' . $this->request->getControllerName();

        if(isset($this->cacheControllers[$controllerName])) {
            // Enable esi tag output
            $this->registerEsiRenderer();
        }

        if ((isset($this->allowNoCacheControllers[$controllerName])
            && $this->request->getQuery('nocache') !== null)
            || $this->response->isRedirect()
            || (!$this->request->getParam('rewriteUrl') && isset($this->controllerOptions[$controllerName]))
        ) {
            $this->response->setHeader('Cache-Control', 'private, no-cache');
        } elseif (isset($this->cacheControllers[$controllerName])) {
            $cacheTime = (int)$this->cacheControllers[$controllerName];
            $this->request->setParam('__cache', $cacheTime);
            $this->response->setHeader('Cache-Control', 'public, max-age=' . $cacheTime . ', s-maxage=' . $cacheTime);
        }

        $shopId = Shopware()->Shop()->getId();
        $allowNoCache = array();
        if(!empty($this->Config()->admin)) {
            $allowNoCache[] = 'admin-' . $shopId;
        }
        if (isset($this->allowNoCacheControllers[$controllerName])) {
            $allowNoCache[] = $this->allowNoCacheControllers[$controllerName] . '-' . $shopId;
        }
        if(!empty($allowNoCache)) {
            $this->response->setHeader('x-shopware-allow-nocache', implode(', ', $allowNoCache));
        }
    }