Trying to get dynamic content with a hole through Magento full glue

I am using Magento Enterprise 1.10.1.1 and you need to get dynamic content on our pages. I insert the current time into the block to quickly see if it works, but cannot go through the cache of the full page.

I tried many implementations found here:

http://tweetorials.tumblr.com/post/10160075026/ee-full-page-cache-hole-punching http://oggettoweb.com/blog/customizations-compatible-magento-full-page-cache/ http: / /magentophp.blogspot.com/2011/02/magento-enterprise-full-page-caching.html

Any decisions, thoughts, comments, tips are welcome.

here is my code:

Application / code / local / Fido / Example / etc. /config.xml

<?xml version="1.0"?> <config> <modules> <Fido_Example> <version>0.1.0</version> </Fido_Example> </modules> <global> <blocks> <fido_example> <class>Fido_Example_Block</class> </fido_example> </blocks> </global> </config> 

Application / code / local / Fido / Example / etc. /cache.xml

 <?xml version="1.0" encoding="UTF-8"?> <config> <placeholders> <fido_example> <block>fido_example/view</block> <name>example</name> <placeholder>CACHE_TEST</placeholder> <container>Fido_Example_Model_Container_Cachetest</container> <cache_lifetime>86400</cache_lifetime> </fido_example> </placeholders> </config> 

Application / code / local / Fido / Example / block / view.php

 <?php class Fido_Example_Block_View extends Mage_Core_Block_Template { private $message; private $att; protected function createMessage($msg) { $this->message = $msg; } public function receiveMessage() { if($this->message != '') { return $this->message; } else { $this->createMessage('Hello World'); return $this->message; } } protected function _toHtml() { $html = parent::_toHtml(); if($this->att = $this->getMyCustom() && $this->getMyCustom() != '') { $html .= '<br />'.$this->att; } else { $now = date('mdY h:i:s A'); $html .= $now; $html .= '<br />' ; } return $html; } } 

Application / code / local / Fido / Example / Model / container / Cachetest.php

 <?php class Fido_Example_Model_Container_Cachetest extends Enterprise_PageCache_Model_Container_Abstract { protected function _getCacheId() { return 'HOMEPAGE_PRODUCTS' . md5($this->_placeholder->getAttribute('cache_id') . $this->_getIdentifier()); } protected function _renderBlock() { $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; } } 

application / design / interface / enterprises / [MyTheme] /template/example/view.phtml

 <?php echo $this->receiveMessage() ?> 

application fragment / design / frontend / enterprise / [mytheme] /layout/catalog.xml

 <reference name="content"> <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml"> <block type="fido_example/view" name="product.info.example" as="example" template="example/view.phtml" /> 
+8
caching enterprise magento hole-punching
source share
1 answer

<name> in the cache.xml file should correspond to the full name of your block in the layout, and not to an alias, for example. <name>product.info.example</name>

Also, _getIdentifier() not implemented on Enterprise_PageCache_Model_Container_Abstract , just remove it from the string returned by your _getCacheId() . If you need to add multiple options, run _getIdentifier() to return the session id or whatever you need.

+15
source share

All Articles