2

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.

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?

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

  • See http://stackoverflow.com/questions/9120413/how-do-i-include-a-dynamic-block-in-the-product-page-with-full-page-caching-turn . Also, your question may be too generalized, so don't be surprised if it gets closed. – benmarks Jul 31 '12 at 17:42
  • i thought the question was actually very specific: how to deal with the core/messages block in a full page cache situation –  Jul 31 '12 at 17:53
  • "This is not directly related to the enterprise edition and how its full page cache and hole punching mechanism might work, just in general.' I've no problem with your question, but these days the diamond crew seem to be closing questions at will. – benmarks Aug 01 '12 at 01:56

1 Answers1

1

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.

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>

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

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

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!

ElGavilan
  • 6,610
  • 16
  • 27
  • 36
Tim Hofman
  • 1,068
  • 7
  • 10