Magento – How to disable cache for particular block in magento2

block-cachemagento2.2

I have created a block in header

<referenceContainer name="columns.top">           
                <block class="XXX\ABC\Block\Category\News" name="news" template="XXX_ABC::catalog/product/news.phtml" cacheable="false" />           
        </referenceContainer>

I need to disable cache for this block for quote.so i use cacheable="false" in this layout.

The cache is disable only for this block in header section (or) full page?

Thanks..

Best Answer

Set your block in controller file :

$resultPage->getLayout()->getBlock('customer_account_navigation');

After add this line in your controller :

$resultPage->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0', true);

Clear cache and check your output.

Related Topic