Exemplo n.º 1
0
 /**
  * Retrieve all identities from blocks for further cache invalidation
  *
  * @param \Magento\Framework\View\Layout $subject
  * @param mixed $result
  * @return mixed
  */
 public function afterGetOutput(\Magento\Framework\View\Layout $subject, $result)
 {
     if ($this->layout->isCacheable() && $this->config->isEnabled()) {
         $tags = array();
         foreach ($this->layout->getAllBlocks() as $block) {
             if ($block instanceof \Magento\Framework\View\Block\IdentityInterface) {
                 $isEsiBlock = $block->getTtl() > 0;
                 $isVarnish = $this->config->getType() == \Magento\PageCache\Model\Config::VARNISH;
                 if ($isVarnish && $isEsiBlock) {
                     continue;
                 }
                 $tags = array_merge($tags, $block->getIdentities());
             }
         }
         $tags = array_unique($tags);
         $this->response->setHeader('X-Magento-Tags', implode(',', $tags));
     }
     return $result;
 }
 /**
  * Set X-Cache-Tags header with all the Magento Cache Tags so
  * they can be purged by the CloudFlare API
  *
  * @param \Magento\Framework\View\Layout $subject
  * @param $result
  * @return mixed
  */
 public function afterGetOutput(\Magento\Framework\View\Layout $subject, $result)
 {
     if (!$subject->isCacheable() || !$this->config->isEnabled()) {
         return $result;
     }
     $tags = [];
     foreach ($subject->getAllBlocks() as $block) {
         if ($block->getIdentities() !== null) {
             $tags = array_merge($tags, $block->getIdentities());
         }
     }
     $tags = array_unique($tags);
     $this->cacheTagsUtil->setCloudFlareCacheTagsResponseHeader($this->response, $tags);
     return $result;
 }
Exemplo n.º 3
0
 /**
  * @param string $xmlString
  * @param bool $result
  * @dataProvider isCacheableDataProvider
  */
 public function testIsCacheable($xmlString, $result)
 {
     $xml = simplexml_load_string($xmlString, 'Magento\\Framework\\View\\Layout\\Element');
     $this->assertSame($this->model, $this->model->setXml($xml));
     $this->assertSame($result, $this->model->isCacheable());
 }
Exemplo n.º 4
0
 /**
  * @return bool
  */
 public function isCacheable()
 {
     return $this->isCacheable && parent::isCacheable();
 }
Exemplo n.º 5
0
 public function testIsNonCacheable()
 {
     $this->_layout->setXml(simplexml_load_file(__DIR__ . '/_files/layout/non_cacheable.xml', 'Magento\\Framework\\View\\Layout\\Element'));
     $this->_layout->generateElements();
     $this->assertFalse($this->_layout->isCacheable());
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function isCacheable()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'isCacheable');
     if (!$pluginInfo) {
         return parent::isCacheable();
     } else {
         return $this->___callPlugins('isCacheable', func_get_args(), $pluginInfo);
     }
 }