Today we discuss about Magento 2 disable cache block .This tutorial include how to disable cache for block. There are two ways to do it. One is disable cache from layout xml for block or disable cache for block is programatically. So let start with our example.
layout cache disable
You can use cacheable=”false” attribute in your layout to disable cache for block but problem is that it will disable whole page cache.
Another option for cache diable
programmatically cache disable
Now the second option is disable cache for block programmatically.
* Simple Hello World Module
* @category QaisarSatti
* @package QaisarSatti_HelloWorld
* @author Muhammad Qaisar Satti
* @Email [email protected]
class HelloWorld extends \Magento\Framework\View\Element\Template
public function getCacheLifetime()