Magento 2 Cacheable False: When to and When Not to Use

What if one small attribute in your layout could make your entire website 50% slower? Not using Magento 2 cacheable false can have such an impact.

With Full Page Cache

100%
Optimal Performance

With Cacheable False

50%
Performance Impact
Performance Guide
Best Practices

Should You Use Cacheable False?

What type of element are you working with?

Code Implementation Examples

Correct Usage
<!-- layout/default.xml -->
<block class="Vendor\Module\Block\Cart"
       name="mini.cart"
       template="Vendor_Module::cart.phtml"
       cacheable="false"/>
Applied to block element displaying user-specific data
Incorrect Usage
<!-- This won't work! -->
<container name="header.panel"
           htmlTag="div"
           cacheable="false">
    <!-- Blocks inside... -->
</container>
Containers don't support cacheable attribute

3 Better Alternatives to Cacheable False

Private Content
JavaScript-based solution
JavaScript Rendering
AJAX-powered content
Edge Side Includes
Varnish-based caching

Private Content

Framework that loads customer-specific content via JavaScript after the page has loaded from cache.

Advantages

  • Keeps Full Page Cache intact
  • Personalizes without server overhead
  • Out-of-the-box support for common blocks
  • Uses Knockout.js and customer-data JS

Best Use Cases

  • Mini-carts and cart counts
  • Welcome messages
  • Customer account links
  • Recently viewed products
Implementation Example:
// In your JavaScript
require(['Magento_Customer/js/customer-data'], function(customerData) {
    var cart = customerData.get('cart');
    cart.subscribe(function(updatedCart) {
        // Update UI with new cart data
    });
});

Quick Comparison

Feature Private Content JS Rendering ESI
Performance Impact Low Low Medium
Setup Complexity Easy Medium Complex
Best For User data Dynamic content High traffic
FPC Compatible

6 Common Challenges and Solutions

Challenge #1

Performance Degradation

Overusing cacheable false forces re-rendering on every request, increasing server load.

Click for solution
Solution

Optimization Strategy

  • Use only for mini-cart or user greetings
  • Load heavy content via AJAX
  • Consider Private Content framework
Click to flip back
Challenge #2

Debug Cache Issues

Identifying which block broke FPC isn't always straightforward.

Click for solution
Solution

Debug Tools

  • Enable developer mode
  • Check X-Magento-Cache-Debug header
  • Use custom logging plugin
Click to flip back
Challenge #3

No Effect Issue

Block still appears cached after marking as cacheable="false".

Click for solution
Solution

Common Causes

  • Clear full_page and layout caches
  • Check parent block caching
  • Verify block isn't JS-rendered
Click to flip back
Challenge #4

Increased TTFB

Uncached blocks increase Time to First Byte significantly.

Click for solution
Solution

Performance Tips

  • Measure with New Relic/Profiler
  • Offload to frontend JS
  • Optimize block logic & queries
Click to flip back
Challenge #5

Logic Conflicts

Mixing block caching with layout cacheable="false" causes issues.

Click for solution
Solution

Best Practices

  • Manage caching only via XML
  • Be consistent in approach
  • Document cache logic clearly
Click to flip back
Challenge #6

Global Cache Disable

One uncacheable block can disable FPC for entire page.

Click for solution
Solution

Isolation Strategy

  • Isolate to specific pages only
  • Use AJAX for user content
  • Move to footer or lazy load
Click to flip back

Best Practices Checklist

When to Use Cacheable False

When NOT to Use Cacheable False

1-2
Ideal number of uncacheable blocks
50%
Potential performance impact
3
Better alternatives available

Frequently Asked Questions

Add cacheable false to the <block> or <referenceBlock> in your layout XML file. It tells Magento to bypass the Full Page Cache for that specific block. It ensures the rendering of the block on each request.

<block name="my.block" cacheable="false"/>

It can impact performance if overused. Uncacheable blocks prevent the caching of the entire page. Use it only when necessary for dynamic or personalized content.

Each uncacheable block can increase page load time significantly

Uncacheable blocks affect the whole page. To isolate dynamic content, use Private Content or AJAX. These methods update specific parts without breaking page caching.

Private Content
Best for user data
AJAX
Best for dynamic updates

Cacheable false disables server-side caching for a block. Private content loads user-specific data via JavaScript after you cache the page. Private content is best for personalization without hurting performance.

Method Cacheable False Private Content
Impact Disables FPC Preserves FPC
Loading Server-side Client-side

Enable developer mode and use the browser's developer tools to inspect headers. Check the X-Magento-Cache-Debug header for cache status. Log or disable blocks to identify which one bypasses FPC.

Enable developer mode
Check X-Magento-Cache-Debug header
Use logging to identify problematic blocks

Still Have Questions?

Consider using managed Magento hosting to handle cacheable blocks efficiently and ensure optimal performance.