购物车(报价)上的全页缓存无效更改 [英] Full Page Cache invalidation on cart (quote) change

查看:64
本文介绍了购物车(报价)上的全页缓存无效更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向迷你购物车块添加一个块(按钮):要么添加到name="cart_sidebar",要么优选添加到name="topCart.extra_actions",因为它呈现为自动为core/text_list类型的子块

I'm trying to add a block (button) to mini cart block: either to name="cart_sidebar" or preferably name="topCart.extra_actions" as it renders it's child block automatically being of core/text_list type

一切正常,除了由于FPC生效而导致产品页面上未调用该功能块之外,其他所有功能都有效.我正在尝试从Enterprise_PageCache_Model_Container_Advanced_Quote类(也尝试过Enterprise_PageCache_Model_Container_Abstract)扩展容器,但是未调用_renderBlock方法.

Everything works great except the block is not getting called on product pages due to FPC being in effect. I'm trying to extend my container from Enterprise_PageCache_Model_Container_Advanced_Quote class (tried Enterprise_PageCache_Model_Container_Abstract as well) however _renderBlock method is not called.

我的cache.xml似乎是正确且有效的:

My cache.xml seems to be correct and valid:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <placeholders>
        <internationalcheckout_international>
            <block>internationalcheckout/international</block>
            <name>internationalcheckout_international</name>
            <placeholder>INT_CHECKOUT</placeholder>
            <container>GSX_InternationalCheckout_Model_Container_Button</container>
            <cache_lifetime>84600</cache_lifetime>
        </internationalcheckout_international>
    </placeholders>
</config>

感谢任何帮助或提示

推荐答案

嵌套动态块

您要尝试的是嵌套动态块,即动态迷你购物车块应包含带有type=internationalcheckout/international的嵌套动态块.

由于FPC处理器实现动态块(打孔)的方式,此方法不起作用.

This does not work because of the way the FPC processor implements dynamic blocks (holepunching).

protected function _processContainers(&$content)
{
    $placeholders = array();
    preg_match_all(
        Enterprise_PageCache_Model_Container_Placeholder::HTML_NAME_PATTERN,
        $content, $placeholders, PREG_PATTERN_ORDER
    );

    // ...
    // ... if applyWithoutApp() on each placeholder then update content
    // ... else prepare data for applyWithApp()
    // ...

    }

FPC处理流程

让我们一步一步地了解会发生什么.

FPC processing flow

Lets go through step by step what happens.

首先,当调用_processContainers()方法时,$content包含缓存的页面,包括所有占位符标记.这还包括您定义的嵌套块.

First, when the _processContainers() method is called, $content contains the cached page, including all placeholder tags. This also includes the nested block you defined.

第二,该方法匹配所有占位符标记.在这之后,$placeholders包括迷你购物车占位符,然后还有嵌套的占位符定义.

Second, the method matches all placeholder tags. After this $placeholdersincludes the mini cart placeholder, and then also your nested placeholder definition.

第三,将按顺序处理找到的占位符.这意味着迷你购物车占位符将在处理嵌套占位符之前进行处理,因为这是preg_match_all()收集匹配项的方式.

Third, the found placeholders are processed in order. This means the mini cart placeholder will be processed before it processes the nested placeholder, because that is how preg_match_all() collects the matches.

第四,实例化了微型购物车.依次实例化checkout/cart_sidebar块,初始化渲染器并在其上调用toHtml().

Fourth, the mini-cart container is instantiated. It in turn instantiates the checkout/cart_sidebar block, initializes the renderers and calls toHtml() on it.

第五,呈现 checkout/cart/cartheader.phtml 模板.当Magento接到电话时

Fifth, the checkout/cart/cartheader.phtml template is rendered. When Magento reaches the call

<?php echo $this->getChildHtml('extra_actions') ?>

它不会为它呈现任何内容,因为在applyWithoutApp()applyWithApp()的处理期间不存在子块.

it won't render any content for it because during the processing of applyWithoutApp() and applyWithApp() no child blocks exist.

第六,FPC处理器将迷你购物车占位符标记的完整内容区域替换为迷你购物车容器返回的呈现内容. $content现在包含更新的迷你购物车html.

Sixth, the FPC processor replaces the complete content area marked by the mini cart placeholder tags with the rendered content returned by the mini cart container. The $content now contains the updated mini cart html.

第七,FPC容器尝试处理嵌套块的占位符.但是$content不再包含占位符标签.通过将包装的迷你购物车占位符替换为新生成的内容,可以删除它们!

Seventh, the FPC container attempts to process the placeholder of your nested block. But the $content no longer contains the placeholder tags for it. They have been removed by replacing the wrapping mini cart placeholder with the new generated content!

当FPC处理内容时,不会加载布局XML,并且不会实例化常规块层次结构.
对于动态(打孔")块,子块的所有输出将被删除,除非块实例本身或容器负责在不加载布局XML的情况下实例化它们. 在FPC处理页面内容时,加载布局XML并生成所有块可能是个糟糕的主意.

When the FPC is processing the content, no layout XML is loaded, and the regular block hierarchy isn't instantiated.
For dynamic ("holepunched") blocks, all output from child blocks will be removed, unless the block instance itself or the container takes care of instantiating them without the layout XML being loaded.
It would be a bad idea performance wise to load the layout XML and generate all blocks while the FPC is processing page content.

这归结为topCart.extra_actions容器块看起来是个好主意,但它与FPC不兼容:(

What this boils down to is that the topCart.extra_actions container block looks like a good idea, but it's not compatible with the FPC :(

您不能在动态块中使用子块.

You can't use child blocks within dynamic blocks.

要实施解决方法,您必须将代码块移至cart_sidebar代码块之外.

To implement a workaround you will have to move your block outside of the cart_sidebar block.

这篇关于购物车(报价)上的全页缓存无效更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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