在单页上禁用/绕过 Magento 全页缓存 [英] Disable/Bypass Magento Full Page Cache on single page

查看:23
本文介绍了在单页上禁用/绕过 Magento 全页缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何禁用或绕过单个页面的 FPC?我不想使用打孔,因为页面上有几个块我需要是动态的,我宁愿修改一个配置/类来指定不应缓存整个页面(类似于结帐的行为).

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).

我对 FPC 的理解是它不用于会话用户"(登录、添加到购物车等).但是,当用户登录时,我看到 FPC 会影响页面.如果我禁用 FPC,则页面会按预期工作.

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.

推荐答案

这里是针对特定控制器禁用 FPC 的解决方案(也可以扩展到特定操作).

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

首先创建一个 Observer 来监听 controller_action_predispatch 事件:

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');
    }
}

然后将以下内容添加到模块的 config.xml 文件中.这在 部分:

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>

现在 Magento 每次都会为您的页面提供服务并绕过 FPC 请求.

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

这篇关于在单页上禁用/绕过 Magento 全页缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆