🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Disable Cache for Block Using XML in Magento 2

By Sanjay JethvaUpdated on May 22, 2025 1 min read

The Magento 2 caching is important for page load speed. Nevertheless, it causes trouble with the customizations that require the dynamic content output.

Not all the time can you go for the caching, based on your business requirements. But there’s a way out. You can disable cache for particular blocks only.

This way, you can disable cache for block using XML in Magento 2. For example, you have implemented a block that behaves differently for the desktop and mobile. If the user accesses it from desktop and then from mobile, he should see the difference which can be possible only if it is disabled to fetch the value from the cached version.

To implement such functionalities where you want Magento 2 to not fetch the cached version, use the solution below!

Method to Disable Cache for Block Using XML in Magento 2:

Add this cacheable=”false” into the XML file like:

<block class="Block\Class" name="blockname" cacheable="false"/>
for example : [Vendor]\[Module]\view\frontend\layout\checkout_cart_index.xml
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="checkout_cart_item_renderers"/>
    <body>
    <referenceContainer name="content">
        <block class="[Vendor]\[Module]\Block\Custom" template="[Vendor]_[Module]::custom.phtml" before="-"
               name="custom_index" cacheable="false"/>
    </referenceContainer>
    </body>
</page>

That’s it.

Use this method when you want to disable the cache for a particular block.

Please feel free to share the solution with fellow developers via social media.

Thanks.

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.