0

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.

1

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>
  • 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 '16 at 10:26
  • have you check with cacheable=false in your block – Rakesh Jesadiya Jun 13 '16 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 '16 at 10:38
  • Basically I want to disable caching for my home_cms page, how would I do that? – Max Oct 19 '16 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 '17 at 5:53

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.