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..

  • 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? – Mano M Jun 8 '18 at 6:29
  • please check my answer. – Rohan Hapani Jun 8 '18 at 8:37
1

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.

  • It use to clear cache only for mentioned block? – Mano 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 – Mano 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); – Mano M Jun 8 '18 at 9:12
  • Still not working – Mano M Jun 8 '18 at 9:12
0

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

  • 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... – Mano 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 ... – Mano M Jun 8 '18 at 8:45
0

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 -

https://devdocs.magento.com/guides/v2.2/extension-dev-guide/cache/page-caching/public-content.html

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.