11

How can I disable or bypass FPC for a single page? I don't want to use hole-punching as there are several blocks on the page that I need to be dynamic and I would rather modify one config/class to specify that the entire page should not be cached (similar to the behavior of checkout).

My understanding of FPC was that it was not used for "session users" (logged in, added to cart, etc...). However, I'm seeing FPC affect pages when a user is logged in. If I disable FPC, then the page works as desired.

Joe Constant
  • 812
  • 2
  • 13
  • 29

3 Answers3

18

Here is the solution for disabling FPC for a specific controller (could be extended to specific action as well).

First create an Observer to listen on the controller_action_predispatch event:

public function processPreDispatch(Varien_Event_Observer $observer)
{
    $action = $observer->getEvent()->getControllerAction();

    // Check to see if $action is a Product controller
    if ($action instanceof Mage_Catalog_ProductController) {
        $cache = Mage::app()->getCacheInstance();

        // Tell Magento to 'ban' the use of FPC for this request
        $cache->banUse('full_page');
    }
}

Then add the following to your config.xml file for the module. This goes in the <frontend> section:

<events>
    <controller_action_predispatch>
        <observers>
            <YOUR_UNIQUE_IDENTIFIER>
                <class>YOURMODULE/observer</class>
                <method>processPreDispatch</method>
            </YOUR_UNIQUE_IDENTIFIER>
        </observers>
    </controller_action_predispatch>
</events>

Now Magento will serve up your page every time and bypass FPC for the request.

Roman Snitko
  • 3,655
  • 24
  • 29
Joe Constant
  • 812
  • 2
  • 13
  • 29
  • what if I want to use it for CMS page? I can use the xml part in update xml of CMS page but I don't knpw what to write in class tag – Nickool Jan 30 '15 at 00:27
  • Thx, I digged around the code of FPC, so far this look the best approach. The interesting entry point could be `Mage_PageCache_Model_Processor` but it cannot be override, because it is initialized with `new ..` ( at least at the beginning ... second time a sigleton is used ... ) – WonderLand Oct 29 '15 at 05:25
  • can someone tell me, what should I write instead of "your unique identifier"? thx :) – Attila Naghi Feb 09 '16 at 07:56
  • @Chester literally_anything_you_want_as_long_as_it_is_unique. Though typically you should at least prefix it with the shortname of your module. – Joe Constant Feb 10 '16 at 15:28
5

Just got done wrestling with Magento EE FPC not displaying core messages on cached CMS pages. Core messages worked fine on cache category and product pages but not CMS pages. I found by passing a certain parameter to a page you can force that pages to be generated instead of server out of the cache.

found in: app/code/core/Enterprise/PageCache/Model/Processor/Default.php

/**
 * Disable cache for url with next GET params
 *
 * @var array
 */
protected $_noCacheGetParams = array('___store', '___from_store');

So it is possible to make a link that has a HTTP GET query string that would bypass the FPC.

http://www.domain.com/?___store

This helped solve a problem I was having were a plugin was redirecting to a referring url with a session message but if the referrer was a CMS page the message would not be displayed until a non-CMS page was viewed.

Ian at SSU
  • 409
  • 3
  • 17
  • 1
    Stores with hundreds of thousands of products will experience heavy server loads if FPC is bypassed, which makes this a potential vector for DDOS attacks. Is there a way to prevent this behavior? – Alex Oct 16 '12 at 08:16
  • Agree this could be a potential issue for large catalogs. Looks like a custom module to alter this behavior would be the way. – Ian at SSU Dec 03 '12 at 04:31
  • Generally when dealing with EE FPC caching messages it's because you're probably trying to output them with getGroupedHtml(). You need to use just toHtml() in order to make sure that the Enterprise hold punching for messaging works correctly. – CVEEP Jun 26 '13 at 18:40
0

Magento's FPC is one complicated beast.

I've overcome this using the following tutorial:

http://oggettoweb.com/blog/customizations-compatible-magento-full-page-cache/

This might be what you're referring to as "Hole Punching", but it's the only way I've found to overcome it.

Magento Guy
  • 2,493
  • 1
  • 16
  • 13
  • Yes, that is hole punching. I tried following the instructions from the link, but I keep getting: "Fatal error: Maximum function nesting level of '200' reached, aborting!" (the number doesn't matter. I've tried increasing the maximum and it just keeps hitting it) when FPC is enabled. Looks like there is a loop gone wild somewhere. If I turn off FPC, everything works fine again. – Joe Constant Dec 09 '11 at 00:08
  • 2
    That's why single link answers are bad. The URL is dead, your answer is useless. – user487772 Oct 05 '14 at 07:17
  • https://web.archive.org/web/20140218205557/http://oggettoweb.com/blog/customizations-compatible-magento-full-page-cache/ – Magento Guy Nov 26 '14 at 06:29