How to clean or flush cache programmatically in magento 2?

Many times we need to clear cache programmatically or using an external script, Using below code snippet we can clear of flush cache programmatically,

Call function like below,
$productStockById = $block->cacheClear();

Get the list of all cache type by just below way,

Result like below type of all cache,

If you want to flushAll cache, Use below methods,

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *