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:

In Magento 2, we can use the following code:

  • Define constructor

  • Use code to clear/flush cache

  • You can edit $types variable if you only want to clear some cache types.

 

 

That’s how we can clear – flush cache in Magento 2. Hope this post will be helpful.

Leave a Reply

Your email address will not be published.