Skip to main content

How do I clear the cache in Magento 2 for a single product_id

the best way to do do this is using the below method


$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]);


you need of course to follow the DI to implement this code, I just used this quick way to make it easy to understand