/** * Is varnish cache engine enabled * * @return bool */ protected function isVarnishEnabled() { if ($this->isVarnishEnabled === null) { $this->isVarnishEnabled = $this->_config->getType() == \Magento\PageCache\Model\Config::VARNISH; } return $this->isVarnishEnabled; }
/** * If Built-In caching is enabled it collects array of tags * of incoming object and asks to clean cache. * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { if ($this->_config->getType() == \Magento\PageCache\Model\Config::BUILT_IN && $this->_config->isEnabled()) { $object = $observer->getEvent()->getObject(); if ($object instanceof \Magento\Framework\DataObject\IdentityInterface) { $tags = $object->getIdentities(); if (!empty($tags)) { $this->getCache()->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array_unique($tags)); } } } }
/** * If Built-In caching is enabled it collects array of tags * of incoming object and asks to clean cache. * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { if ($this->_config->getType() == \Magento\PageCache\Model\Config::BUILT_IN && $this->_config->isEnabled()) { $object = $observer->getEvent()->getObject(); if ($object instanceof \Magento\Framework\Object\IdentityInterface) { $tags = $object->getIdentities(); foreach ($tags as $tag) { $tags[] = preg_replace("~_\\d+\$~", '', $tag); } $this->_cache->clean(array_unique($tags)); } } }
/** * 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 ($subject->isCacheable() && $this->config->isEnabled()) { $tags = []; foreach ($subject->getAllBlocks() as $block) { if ($block instanceof \Magento\Framework\DataObject\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; }
/** * Add comment cache containers to private blocks * Blocks are wrapped only if page is cacheable * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { $event = $observer->getEvent(); /** @var \Magento\Framework\View\Layout $layout */ $layout = $event->getLayout(); if ($layout->isCacheable() && $this->_config->isEnabled()) { $name = $event->getElementName(); $block = $layout->getBlock($name); $transport = $event->getTransport(); if ($block instanceof \Magento\Framework\View\Element\AbstractBlock) { $blockTtl = $block->getTtl(); $varnishIsEnabledFlag = $this->_config->getType() == \Magento\PageCache\Model\Config::VARNISH; $output = $transport->getData('output'); if ($varnishIsEnabledFlag && isset($blockTtl)) { $output = $this->_wrapEsi($block, $layout); } elseif ($block->isScopePrivate()) { $output = sprintf('<!-- BLOCK %1$s -->%2$s<!-- /BLOCK %1$s -->', $block->getNameInLayout(), $output); } $transport->setData('output', $output); } } }
/** * Flash Built-In cache * * @param \Magento\Framework\Event\Observer $observer * @return void * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function flushAllCache(\Magento\Framework\Event\Observer $observer) { if ($this->_config->getType() == \Magento\PageCache\Model\Config::BUILT_IN) { $this->_cache->clean(); } }
/** * Flash Built-In cache * * @return void */ public function execute() { if ($this->_config->getType() == \Magento\PageCache\Model\Config::BUILT_IN) { $this->_cache->clean(); } }