Magento 2 clear – flush cache programmatically
Magento 2 clear – flush cache programmatically. In this post, let’s find out how to clear/flush cache programmatically in Magento 2. It will be useful for you in your custom module or new feature. In Magento 1, it’s quite simple using:
1 2 3 4 5 |
Mage::app()->cleanCache(); or Mage::app()->getCacheInstance()->flush(); |
In Magento 2, we can use the following code: Define constructor
1 2 3 4 5 6 7 8 9 |
public function __construct( Context $context, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool ) { parent::__construct($context); $this->_cacheTypeList = $cacheTypeList; $this->_cacheFrontendPool = $cacheFrontendPool; } |
Use code … Continue reading Magento 2 clear – flush cache programmatically