Wednesday, 8 May 2019

Magento 2 full page cache invalidates every time

We have found a quick fix without any issues. Go To this file and update below changes.

/vendor/magento/module-page-cache/Observer/FlushCacheByTags.php

Line no 57
Replace this function
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 (!is_object($object)) {
                return;
            }
            $tags = $this->getTagResolver()->getTags($object);

            if (!empty($tags)) {
                $this->getCache()->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array_unique($tags));
            }
        }
    }
 
 
To

 
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 (!is_object($object)) {
                return;
            }
            $tags = $this->getTagResolver()->getTags($object);

            if (!empty($tags)) {
                $this->getCache()->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, array_unique($tags));
            }
        }
    }
   

 In both function change only  CLEANING_MODE_MATCHING_ANY_TAG from CLEANING_MODE_MATCHING_TAG   
   
After the update a code it's working in my case.

No comments:

Post a Comment