how disable cache in price's block on product view to magento2.3?

how disable cache in price's block on product view to magento2.3?

August 24, 2026 · Illustrated author avatarBy Stefan Bogdanescu
how disable cache in price's block on product view to magento2.3?

Disabling Cache for Price Blocks on Product View in Magento 2.3

If you’re looking to disable caching for price blocks when viewing products in your Magento 2.3 store, you’ve come to the right place. In this guide, we’ll explore why using cacheable="false" might not work as expected and provide a comprehensive solution.

Understanding Cacheable Attribute

The cacheable attribute is used to indicate whether a block should be stored in the cache or rendered fresh each time it’s requested. Setting cacheable="false" tells Magento not to store the output of this block in the cache, ensuring it’s always rendered freshly for each request.

However, using this attribute directly in your layout XML isn’t enough when dealing with price blocks provided by Magento’s Pricing module.

Why cacheable=“false” Doesn’t Work

There are a few reasons why simply setting cacheable="false" might not disable caching for the price block on product view:

  1. Caching at Renderer Level: The pricing renderer itself might have its own caching mechanism that isn’t controlled by the layout XML.
  2. Composite Design Pattern: Magento’s Pricing module uses a composite design pattern, which can make it challenging to control caching at the individual block level.

Solving the Issue: Override the Price Renderer

To effectively disable caching for the price block on product view, you’ll need to override the pricing renderer and manually disable its caching mechanism. Here’s how:

  1. Create a Custom Renderer: In your custom module, create a new file named catalog_price_render.php inside the etc/di.xml directory.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Pricing\Render">
        <arguments>
            <argument name="productCacheTypePool" xsi:type="array">
                <item name="catalog_product_price" xsi:type="string">Magento\Catalog\Model\Product\Price\CacheTypePool</item>
            </argument>
        </arguments>
    </type>
</config>
  1. Disable Caching in Your Custom Renderer: Create a new file named PriceRender.php inside the etc/di.xml directory of your custom module.
namespace Magento\Catalog\Pricing;

class PriceRender implements \Magento\Framework\View\Element\Block\ArgumentInterface
{
    // Override the constructor to disable caching for product price

    public function __construct(
        TemplateFactory $priceTemplateFactory,
        \Magento\Catalog\Model\Product\Visibility $productVisibility,
        \Magento\Catalog\Model\Config $catalogConfig,
        \Magento\Customer\Model\Session $customerSession,
        \Magento\Framework\Pricing\Render $renderStrategy,
        \Magento\Framework\App\RequestInterface $request,
        \Magento\Store\Model\StoreManagerInterface $storeManager
    ) {
        // Insert your logic here to disable caching for the price render

        // You can use Magento's built-in cache management services or implement a custom mechanism
    }
}

Conclusion: Disabling Cache Effectively

Disabling cache for price blocks on product view in Magento 2.3 requires more than just setting cacheable="false" in your layout XML. By overriding the pricing renderer, you gain direct control over its caching behavior.

Remember that changing core files directly is generally discouraged due to upgrade compatibility issues. Instead, consider creating a custom module to override the necessary classes and maintain separation of concerns in your codebase.

For more insights on Magento 2 development best practices, feel free to explore our blog at Laravel Company. We cover a wide range of Magento-related topics to help you make informed decisions when building your e-commerce store.

Magento 2 Catalog Cache Extensions

Our network