cache

Magento 2 Block Cache

Caching plays an essential role in improving the page load time. In this article, I want to show you five blocks cache in Magento 2, or five approaches to caching, and when and how to use them. Interestingly, this article will cover both full page and block cache. Let’s explore each type of block cache together!

In case, cache_lifetime of the block is set to a number greater than 0, the block is cacheable

 

to cache any block, you need to override this function 

 

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

 

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