I need to remove the product_list block from cache Class: Magento\Catalog\Block\Product\ListProduct Block: /var/www/html/vendor/magento/module-catalog/view/frontend/templates/product/list.phtml
I have tried these solutions:
public function getCacheLifetime()
{
return null;
}
I have tried $_isScopePrivate = true; too.
Nothing seems to be working. I need to update the product collection on category list page based upon user input, so I need to remove the block from cache. Please help.
1 Answer 1
Are you sure, that this is a good idea? because all pages with non cached blocks are excluded from full page caching. in your case, all category pages are excluded from full page caching. i think, you have to solve your problem with dynamic loaded content.
if you really want to disable the cache for a specific magento block, you can do it in a xml file. See here.
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="category.products">
<block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" template="Magento_Catalog::product/list.phtml" cacheable="false"/>
</referenceContainer>
</body>
</page>
-
Hi, putting cacheable="false" will remove entire page from cache, won't it?Manish Joy– Manish Joy2022年07月01日 08:44:41 +00:00Commented Jul 1, 2022 at 8:44
-
yes. all pages with a non cacheable block on it are excluded from full page cache.Philippe Aellig– Philippe Aellig2022年07月01日 09:25:49 +00:00Commented Jul 1, 2022 at 9:25
-
So, this is not what I need to achieve. I just need my block out of the cache which is not working for me.Manish Joy– Manish Joy2022年07月01日 09:36:14 +00:00Commented Jul 1, 2022 at 9:36
-
yes, but if you have just one block on a page, the whole page is excluded from full page cache. this is a magento behavior. if you can live with that, try the xml solution in my answer to exclude the block from cache.Philippe Aellig– Philippe Aellig2022年07月01日 11:38:05 +00:00Commented Jul 1, 2022 at 11:38
-
Sorry, this solution won't work as we definitely cannot exclude entire page from FPC.Manish Joy– Manish Joy2022年07月05日 06:31:06 +00:00Commented Jul 5, 2022 at 6:31
Explore related questions
See similar questions with these tags.