如果启用全页缓存,企业版控制器事件不会触发

发布于 2024-10-12 15:15:48 字数 961 浏览 2 评论 0原文

因此,在我们最近的一次发布中,我们观察了很多事件,例如controller_action_predispatch。网站上线后,我们开始注意到我们的观察员从未被要求进行这些操作。经过一番调查后,我们的一位开发人员在 Mage_Core_Model_App 中第 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();
        }

,您可以看到 $this->_cache->processRequest() 是否为真,而当启用全页缓存时,您永远不会得到到调度。开发人员确实找到了 http_response_send_before ,无论哪种方式都会被调用,但在我看来这是一个错误,或者如果您启用了全页缓存,则永远不应该将这些控制器调度事件用于任何事情。有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

妞丶爷亲个 2024-10-19 15:15:48

考虑到全页缓存的性质,我将其称为“按预期工作”。虽然没有触发某些事件可能有点奇怪,但他们必须选择一条线,这对我来说很有意义,特别是因为控制器从未真正被调度。

您应该将这些控制器调度事件用于影响页面的任何内容(因为它仍然需要生成),但如果您将其用于跟踪等,那么它是不合适的。

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.

大姐,你呐 2024-10-19 15:15:48

如果您想了解缓存如何与 Magento Enterprise 配合使用,请参阅此处

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

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

瑾夏年华 2024-10-19 15:15:48

启用或未启用全页缓存唯一可靠的侦听事件是 http_response_send_before

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

人│生佛魔见 2024-10-19 15:15:48

controller_front_send_response_before

无论是否启用 FPC,都会触发此事件

controller_front_send_response_before

This event will be fired irrespective of FPC enabled

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文