Magento2 Refresh Cache for Single Product
Magento’s cache management system saves loaded data, configuration, instructions, images, assets, and more for increased performance loading and rapid access on the storefront. It offers increased stability on your website during heavy user load and greater customer browsing activity. Having a slow-performing website can also negatively impact your conversion
You can use this code to refresh the cache for single product
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productR = $objectManager ->create('\Magento\Catalog\Api\ProductRepositoryInterface'); $product = $productR->get('product_sku'); $product->cleanCache(); $this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $product]);
Please initialize the objectManager and ProductRepository in your constructor