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

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

3 Answers 3

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.

8
  • It use to clear cache only for mentioned block?
    – Mahi M
    Commented Jun 8, 2018 at 8:44
  • Yes. It's use for specific block. As per my answer, It will just use for customer_account_navigation block only. Commented Jun 8, 2018 at 8:44
  • Ok..i will try that
    – Mahi M
    Commented Jun 8, 2018 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
    Commented Jun 8, 2018 at 9:12
  • Still not working
    – Mahi M
    Commented Jun 8, 2018 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

3
  • 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
    Commented Jun 8, 2018 at 6:33
  • On which page you want to quote items? Commented Jun 8, 2018 at 7:37
  • In list page ...
    – Mahi M
    Commented Jun 8, 2018 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 and acknowledge you have read our privacy policy.

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