Full page cache, block update

Full page cache, block update

September 12, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Full page cache, block update

Implementing Full Page Cache in Magento: Dealing with Block Updates

In modern e-commerce development, implementing full page cache is essential for optimizing performance and improving user experience. While Magento offers robust caching mechanisms out of the box, dealing with dynamic content like adding products to a cart can be challenging.

The Challenge: Updating Specific Blocks During Cart Addition

When a user navigates your Magento store and adds a product to their cart, certain blocks on the page need to be updated to reflect this change. These might include mini-carts, product availability indicators, or dynamic pricing blocks. The key issue is how to selectively update these specific blocks without invalidating the entire page cache.

Best Practices for Handling Cache Updates

1. Disable Caching for Post Requests

The first step is to disable caching for post requests entirely. This ensures that critical operations like adding products to a cart are not cached, preventing outdated data from being served to users.

To do this in Magento, you can override the Mage_Core_Controller_Varien_Action class and extend its _enableLayout() method:

public function _enableLayout()
{
    if (strtoupper($this->getRequest()->getMethod()) == 'POST') {
        $this->_isLayoutLoaded = true;
        return;
    }

    parent::_enableLayout();
}

2. Implement a “Placeholder” Block

For blocks that need to be updated, you can create a placeholder or “dummy” version of the block and swap it with the actual content when necessary.

Here’s how you can achieve this:

  • Create an XML layout file (e.g., catalog.xml) in your custom theme.
  • Define a new block type for each block that needs to be updated, using a unique identifier.
  • Replace the original block with the placeholder block in the layout files.

For example:

<block type="catalog/product_placeholder" name="product.info.dummy" as="product_info" template="catalog/product/placeholder.phtml"/>

In your custom theme’s catalog/product/placeholder.phtml file, you can include a simple message or empty content that will be displayed when the block is cached.

3. Update Blocks Dynamically

When the user adds a product to their cart (a post request), you need to update the necessary blocks dynamically without invalidating the entire page cache.

You can achieve this by using JavaScript to make an AJAX request and then updating the DOM elements directly. This approach allows for selective updates of specific blocks while keeping other cached content unaffected.

Here’s a high-level overview:

  1. In your controller, handle the post request that adds the product to the cart.
  2. After processing the request successfully, return a JSON response containing the updated block data or a unique identifier.
  3. On the client-side, listen for the AJAX response using JavaScript.
  4. Once the response is received, use the updated data or identifier to dynamically update the corresponding blocks in the DOM.

Conclusion: Selective Cache Updates and Dynamic Content

Implementing full page cache in Magento requires careful handling of dynamic content like updating specific blocks during cart addition. By disabling caching for post requests and using placeholder blocks combined with AJAX updates on the client-side, you can achieve selective updates without invalidating the entire page cache.

Remember that optimizing performance is an ongoing process, and it’s essential to monitor your store’s behavior and make adjustments as needed.

For more advanced caching techniques and Magento-specific best practices, I recommend exploring the official documentation or seeking expert advice from professional e-commerce developers at LaravelCompany.

Happy coding!

Checkout Catalog Cache Performance

Our network