本文介绍了如何处理Magento打孔中的消息块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对整页缓存情况下的magento打孔如何工作感兴趣.总体而言,这与企业版及其全页缓存和打孔机制如何工作没有直接关系.

I am getting interested in how hole punching might work in magento inside a full page cache situation. This is not directly related to the enterprise edition and how its full page cache and hole punching mechanism might work, just in general.

由于magento生成消息块的方式,我真的很好奇在打孔情况下如何处理消息块?

Due to the way that the messages block is generated by magento i am really very curious as to how to deal with the messages block in a hole punching situation?

以前有没有magento开发人员解决过这个问题,也许可以向我解释如何对这个特定的块进行打孔?

Have any magento devs out there tackled this before and can maybe explain to me how this particular block can be hole punched?

推荐答案

您需要将缓存容器链接到core/messages块,以防止该块被缓存.为了实现您的目标,您将需要一个基本模块,或将其添加到您现有的模块之一中,以最适合您的位置(阅读:更合逻辑)为准.

You will need to link a cache container to the core/messages block to be able to prevent the block from caching. To reach your goal you will need a basic module, or add this to one of your existing module, whichever is the best (read: more logical) place for you.

your_module/etc/内,您将需要创建cache.xml文件:

Within your_module/etc/ you will need to create cache.xml file:

<config>
    <placeholders>
        <your_module_messages>
            <block>core/messages</block>
            <placeholder>SYSTEM_MESSAGES</placeholder>
            <container>Your_Module_Model_PageCache_NoCache</container>
        </your_module_messages>
     </placeholders>
 </config>

Your_Module_Model_PageCache_NoCache必须是Enterprise_PageCache_Model_Container_Abstract的扩展,在该扩展中,您需要覆盖saveCache()方法并直接返回$this,而不是触发基础$this->_saveCache().也许可以通过更多的逻辑使此打孔变得更聪明,但现在假设您永远不知道何时有新消息,从而始终使该漏洞处于打开状态.

The Your_Module_Model_PageCache_NoCache needs to be an extend of Enterprise_PageCache_Model_Container_Abstract and in that extend you need to overwrite the saveCache() method and directly return $this instead triggering the underlying $this->_saveCache(). Perhaps with more logic you can make this punch hole a bit smarter, but for now assume that you never know when there is a new messages, thus leaving the hole open at all times.

public function saveCache($blockContent)
{
    return $this;
}

剩下的唯一事情就是触发Magento从整个内部加载core/messages块.您可以通过在类中添加以下方法来完成此操作.

The only thing left is to trigger Magento to load the core/messages block from within the whole. This you can accomplish by adding the following method to your class.

protected function _renderBlock()
{
    $block = $this->_placeholder->getAttribute('block');
    //$template = $this->_placeholder->getAttribute('template');

    $block = new $block;
    //$block->setTemplate($template);
    $block->setLayout(Mage::app()->getLayout());

    return $block->toHtml();
}

它将从cache.xml文件中获取块信息,并返回该块的输出.由于core/messages实际上生成了它自己的HTML,因此您无需提供模板.因此最好从代码中删除那些注释行.

It will fetch the block information from the cache.xml file and return the output of the block. Since core/messages actually generated it's own HTML you don't need to provide a template. So might as well remove those commented lines from the code.

希望这可以帮助您完成任务!

Hopefully this helps you with your task at hand!

这篇关于如何处理Magento打孔中的消息块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 16:44