Magento – Issues in implementing Holepunching in Magento FPC

cacheee-1.11full-page-cacheholepunching

I have a block close to what the 'welcome' block in the header is but slightly different.
Holepunching does not seem to be working for me I have mostly referred to
this link.

Here's my code:

I have this block called in the layouts catalog.xml

<catalog_product_view translate="label">
    <label>Catalog Product View (Any)</label>
    <!-- Mage_Catalog -->
    <reference name="root">
        <action method="setTemplate"><template>page/newOneColumn.phtml</template></action>
        <block type="page/html_welcomeuser" name="welcome_user" template="page/html/welcomeuser.phtml" />
        <block type="core/text_list" name="top-nav" />
    </reference>

Here's my Main block: (Don't ask my Mage was overridden in local, its how it we got from third party)

class Mage_Page_Block_Html_Welcomeuser extends Mage_Core_Block_Template
{

    /**
     * 
     * @return type
     */  
    public function getCacheKeyInfo() {
      $info = parent::getCacheKeyInfo();
      $info['customer_id'] = Mage::getSingleton('customer/session')->getCustomerId();
      return $info;
    }    


}

The welcomuser.phtml:
– Has calls to get the username from a helper. excluded

Here's My Holepunching implementation:

Create new module attaching the cache.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <placeholders>
        <welcome_user_cache>
            <block>page/html_welcomeuser</block>
            <name>welcome_user</name>
            <placeholder>WELCOME_USER</placeholder>
            <container>Mymodule_Holepunch_Model_Container_Welcomeuser</container>
            <cache_lifetime>86400</cache_lifetime>
        </welcome_user_cache>
    </placeholders>
</config>

Coming to the Container:

class Mymodule_Holepunch_Model_Container_Welcomeuser extends Enterprise_PageCache_Model_Container_Abstract
{

    protected function _getIdentifier()
    {
        Mage::log('Inside getIdentifier', null, 'cache.log');
        $cacheId = $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER, '')
            . '_'
            . $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER_LOGGED_IN, '');
        return $cacheId;
    }

    /**
     * Get cache identifier
     *
     * @return string
     */
    protected function _getCacheId()
    {
        Mage::log('Inside getCacheId', null, 'cache.log');
        return 'CONTAINER_WELCOMEUSER_' . md5($this->_placeholder->getAttribute('cache_id') . $this->_getIdentifier());
    }

    /**
     * Render block content
     *
     * @return string
     */
    protected function _renderBlock()
    {
        Mage::log('Inside renderBlock', null, 'cache.log');
        $blockClass = $this->_placeholder->getAttribute('block');
        $template = $this->_placeholder->getAttribute('template');

        $block = new $blockClass;
        $block->setTemplate($template);
        return $block->toHtml();
    }


    protected function _saveCache($data, $id, $tags = array(), $lifetime = null) { return false; }    

}

Problems:

  • The same "Hello firstname>" block (cached firsttime) appears to all users. Where am I going wrong? About to pull my hair over this. I am sure I am missing something?
  • If you observe I have put Mage::log statements in the container, but nothing seems to be logging.

Edit:

Attaching config.xml of my holepunch Module:

<?xml version="1.0"?>
<config>
    <modules>
        <Mymodule_Holepunch>
            <version>0.1.0</version>
        </Mymodule_Holepunch>
    </modules>
    <global>
        <models>
            <mymodule_holepunch>
                <class>Mymodule_Holepunch_Model</class>
            </mymodule_holepunch>
        </models>
        <blocks>
            <mymodule_holepunch>
                <class>Mymodule_Holepunch_Block</class>
            </mymodule_holepunch>
        </blocks>
    </global>
</config>

Best Answer

Ref: https://stackoverflow.com/questions/8126548/trying-get-dynamic-content-hole-punched-through-magentos-full-page-cache

The <name> in the cache.xml must match your blocks full name in the layout, not the alias, e.g. <name>product.info.example</name>

Related Topic