I have created a new block to sit on the product detail page which contains dynamic content (the customer's recently-viewed products) that should not be cached. How can I switch off caching for that particular block?

I've tried the method mentioned in How to disable the cache for the block in Magento 2?, setting _isScopePrivate to false. That doesn't work, the block is still cached.

I have also tried disabling the cache for the whole page, which is not what I want but thought I'd see what happened. The page is still cached.

I have cleared out all folders under var and pub/static as well as running cache:clean. I have checked and the generated XML file definitely has cacheable="false" on the new block. But the page is still cached. This makes me think there is something else I'm missing.

3 Answers 3


You can't disable single block cache like in magento 1,

Magento recommends handling customer related data via ajax.

So you need to create an api endpoint or section data and use javascript to retrieve the data and load it on front :)



There are some ways to do this task :

  1. use cacheable="false" but it's not recommended because it will disable full page cache so it's bad for performance

2 try this

    protected function _construct()
            'cache_lifetime' => false,
            'cache_tags' => ['Rokanthemes_Themeoption', \Magento\Store\Model\Group::CACHE_TAG],


    public function getCacheLifetime()
    return false;

You can just use cacheable="false" for your block to disable cache for that block. This is magento 2 core strucuture to disable specific block cache. you can try in your block xml file.

core ex.

<block class="Magento\Checkout\Block\Cart" name="checkout.cart" template="cart.phtml" cacheable="false"></block>
  • 2
    Thanks for taking the time to answer, however as I said in my question there are two problems with this. 1) It doesn't work. 2) It would not be a viable solution since (as far as I know) it disables the cache for the whole page, rather than just the block.
    – piemanji
    Jun 13, 2016 at 10:26
  • have you check with cacheable=false in your block Jun 13, 2016 at 10:37
  • This is what I have in my layout XML file: <block class="Namespace\Module\Block\Product\View\RecentlyViewed" name="product.info.recentlyviewed" template="Namespace_Module::product/view/recentlyviewed.phtml" before="-" cacheable="false" />
    – piemanji
    Jun 13, 2016 at 10:38
  • Basically I want to disable caching for my home_cms page, how would I do that?
    – Max
    Oct 19, 2016 at 8:57
  • Be aware that this will disable full page cache for any page that your block appears on. See here: devdocs.magento.com/guides/v2.2/extension-dev-guide/cache/…
    – Wildcard27
    Oct 26, 2017 at 5:53

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.