如何为购物车块实施magento高速缓存打孔 [英] How to implement magento cache hole punching for shopping cart block

查看:76
本文介绍了如何为购物车块实施magento高速缓存打孔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Magento EE版本1.12,并且启用了全页缓存

Im using Magento EE version 1.12 with Full page cache enabled

a)我的产品详细信息页面已缓存 b)因此,我在此页面中的购物车未显示动态商品数 c)所以我无法在我的产品详细信息页面上显示有效的购物车数量

a) my product detail page is cached b) as a result my shopping cart in this page doesn't show dynamic item count c) so i am not able to show valid cart item count in my product detail page

我遵循的步骤

1)我创建了一个块并从header.phtml调用 2)尝试使topcart.phtml块不被缓存

1) I created a block and called from header.phtml 2) trying to make that topcart.phtml block not to be cached

作为magento的新手,我得到了一些用于高速缓存打孔的链接

As im a newbie in magento , i got some links for cache hole punching

我关注了以下链接,但未成功

I followed below links but no success

我的文件结构

应用程序代码-本地-企业-PageCache-> etc-cache.xml

app- code - local - Enterprise - PageCache ->etc - cache.xml

和PageCache-模型-容器-TopCart.php

and PageCache - model -container - TopCart.php

代码如下所示

帮助链接一个

帮助链接两个

链接三个

我创建了文件 cache.xml和cart.php容器文件

i created files cache.xml and cart.php container file

 <page_html_topcart>
        <block>page/html_topcart</block>
        <name>topcart</name>
        <placeholder>PAGE_HTML_HEADER_CART</placeholder>
        <container>Enterprise_PageCache_Model_Container_TopCart</container>
        <cache_lifetime>36400</cache_lifetime>
    </page_html_topcart>

这是我的topcart.php容器文件的样子

this is my topcart.php container file looks like

  protected function _getIdentifier()
{
    $cacheId = $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER, '')
        . '_'
        . $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER_LOGGED_IN, '');

    return $cacheId;
}

 protected function _getCacheId()
{
    return 'CONTAINER_TOPCART_' . md5($this->_placeholder->getAttribute('cache_id') . $this->_getIdentifier());
}

protected function _renderBlock()
{
    $block = $this->_getPlaceHolderBlock(); //('page/html_header_cart');
    Mage::dispatchEvent('render_block', array('block' => $block, 'placeholder' => $this->_placeholder));
    return $block->toHtml();
}

请通过有用的链接和步骤帮助我

kindly help me out with useful links and step

推荐答案

我遇到了同样的问题.因此,我认为问题在于,在这种情况下,我们没有可缓存的模板.因此,如果按照您的方式(和我一样)对它进行高速缓存,您最终将在高速缓存文件中得到base64编码的链接列表.为了验证这一点,我解压缩了var/full_page_cache中的文件-然后我们开始:购物车计数已缓存,即使您的购物车发生更改也不会更改,并且在服务器端也无法替换(至少不能在服务器端替换)干净的方式.)

I faced the same issue. So, i think, the problem is, that we don't have cachable template in this case. So if you cache it the way you did (and as I did, too), you end up in a base64 encoded list of links in your cache file. To validate that, I uncompressed the files in var/full_page_cache - and here we go: the cart count is cached and won't be changed even if your cart changes, and it would be not replaceable on server side (at least not in a clean way).

此行为的原因很简单:对于FPC,仅渲染模板,并传递一些值.但是模板仅在这种特殊情况下呈现列表,仅访问一个块方法(getLinks).在布局xml文件中,您会找到一些"addLink"调用,这些调用将为该块提供数据,这就是为什么所有结果都经过base64编码并最终存储在缓存文件中的原因.您的容器无法访问它们.

The reason for this behaviour is a simple one: For FPC, you render templates only, passing some values. But the template only renders a list in that special case, accessing only one block method (getLinks). In your layout xml files, you will find some calls of "addLink", which feeds that block, that's why all the results become base64 encoded and end up in your cache file. They are not accessable by your container.

但是我认为,有一种解决方法.只需收集要呈现的链接,并为此创建一个自定义模板和一个自定义块.现在,您将能够以适当的方式对其进行缓存.

But I think, there is a way to fix that. Just collect the links you want to be rendered and create a custom template and a custom block for that. You'll now be able to cache it in a proper way.

这篇关于如何为购物车块实施magento高速缓存打孔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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