Skip to main content

Flash Catalog Images Cache Magento2

To flash the Catalog Images cache, first of all instantiate the Object and Event Manager in your constructor

 

private $objectManager;
private $eventManager;

public function __construct(
    \Magento\Framework\ObjectManagerInterface  $objectManager,
    \Magento\Framework\Event\Manager $eventManager
){
     $this->objectManager = $objectManager;
        $this->eventManager = $eventManager;
 }

After that you can clean the catalog images cache by using this two code lines

$this->objectManager->create(\Magento\Catalog\Model\Product\Image::class)->clearCache();
$this->eventManager->dispatch('clean_catalog_images_cache_after');

to have full review have a look at this controller

\Magento\Backend\Controller\Adminhtml\Cache\CleanImages