Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enterprise Edition Controller events not firing if Full Page Cache is enabled

Tags:

magento

So on one of our recent launches we had a lot of events that we were observer such as controller_action_predispatch. Once the site went live we started noticing that our observers were never getting called for those. After a little investigation one of our developers found this block of code in Mage_Core_Model_App around line 292

if ($this->_cache->processRequest()) {
            $this->getResponse()->sendResponse();
        } else {
            $this->_initModules();
            $this->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);

            if ($this->_config->isLocalConfigLoaded()) {
                $this->_initCurrentStore($scopeCode, $scopeType);
                $this->_initRequest();
                Mage_Core_Model_Resource_Setup::applyAllDataUpdates();
            }

            $this->getFrontController()->dispatch();
        }

As you can see if $this->_cache->processRequest() that is true which it is when full page cache is enabled you never get to the dispatch. The developer did find http_response_send_before which gets call either way but it seems to me like this is a bug or you should never ever use those controller dispatch events for anything if you have full page caching enabled. Any thoughts?

like image 800
dan.codes Avatar asked Jan 19 '11 12:01

dan.codes


3 Answers

Given the nature of the full page caching, I'd call this "works as intended". While it can be a little strange not to have some events firing, they had to pick a line and this one makes sense to me, especially since the controller is never really dispatched.

You should use those controller dispatch events for anything that affects the page (as it still needs to be generated), but if you are using it for tracking and such, no it would not be appropriate.

like image 144
Joe Mastey Avatar answered Nov 07 '22 10:11

Joe Mastey


See here if you want to learn how Caching works with Magento Enterprise

http://magentophp.blogspot.com/2011/02/magento-enterprise-full-page-caching.html

like image 35
Nasaralla Avatar answered Nov 07 '22 11:11

Nasaralla


The only reliable event to listen for with and without Full Page Cache enabled is http_response_send_before.

like image 28
philwinkle Avatar answered Nov 07 '22 09:11

philwinkle