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" />           

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?


  • it will for all. – kunj Jun 8 '18 at 6:28
  • But i need to disable cache for particular block...If any solution for do that? – Mahi M Jun 8 '18 at 6:29
  • please check my answer. – Rohan Hapani Jun 8 '18 at 8:37

Set your block in controller file :


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.

| improve this answer | |
  • It use to clear cache only for mentioned block? – Mahi M Jun 8 '18 at 8:44
  • Yes. It's use for specific block. As per my answer, It will just use for customer_account_navigation block only. – Rohan Hapani Jun 8 '18 at 8:44
  • Ok..i will try that – Mahi M Jun 8 '18 at 8:45
  • In controller file ...$resultPage = $this->_resultPageFactory->create(); $resultPage->getLayout()->getBlock('block_name'); return $resultPage->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0', true); – Mahi M Jun 8 '18 at 9:12
  • Still not working – Mahi M Jun 8 '18 at 9:12

Cacheable and uncacheable pages

Cacheable and uncacheable are terms we use to indicate whether or not a page should be cached at all. (By default, all pages are cacheable.) If any block in a layout is designated as uncacheable, the entire page is uncacheable.

You can see more information Magento dev docs

| improve this answer | |
  • I need to get quote items...But i can't get the data when the cache is enable..If any alternate solution for get quote items... – Mahi M Jun 8 '18 at 6:33
  • On which page you want to quote items? – Suresh Chikani Jun 8 '18 at 7:37
  • In list page ... – Mahi M Jun 8 '18 at 8:45

Using cacheable="false" will make whole page non-cached. So the option is you need to use knockout js to render the non cache content, kind of ajax.

Please check here - https://devdocs.magento.com/guides/v2.2/extension-dev-guide/cache/page-caching/private-content.html

To gave a view how M2 cache system works you can have a view of this ie. page variations and Identity Interface -


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.