{"id":1073,"date":"2013-03-16T15:26:14","date_gmt":"2013-03-16T15:26:14","guid":{"rendered":"http:\/\/invisiblezero.net\/?p=543"},"modified":"2013-03-16T15:26:14","modified_gmt":"2013-03-16T15:26:14","slug":"magento-ee-punch-hole-in-full-page-cache","status":"publish","type":"post","link":"http:\/\/ndthanh.com\/magento-ee-punch-hole-in-full-page-cache\/","title":{"rendered":"Magento EE – Punch Hole in Full Page Cache"},"content":{"rendered":"
<\/p>\n
Magento is slow, it’s a truth . because of its slowness, Magento have some cache mechanisms to make your site faster, so your customers will be happy. Many people choose to use all of caching options available. according to their opinions, the best cache solution for Magento is Full Page Cache (FPC), and it’s one feature from Magento Enterprise.<\/p>\n
implementing FPC means you will have all your page content cached. it’s good for speed, but what will happen when you have several block that need to be updated after each request, or may be you want a shorter cache life for it ? The following tutorial will show you how to punch some holes in your FPC pages so you can solve above problems.<\/p>\n
<\/p>\n
1. i modified layout xml file to set a name to block<\/strong><\/p>\n 2. then i created a new cache.xml file in etc folder under module<\/strong><\/p>\n Notice in the above tags, the tagname should be any unique cache tagname, in our case its ‘myblock_someaction’. The block tag and the name tag should have the block name and the name as it appears in the layout in design. The placeholder tag should have any unique string. The container needs to contain the model which actually defines the behavior of the block cache. And finally, the cache_lifetime is the time till the cache will be valid. Now, all that matters is the model which defines the behavior of the cache and we hope to look it in details.<\/p>\n finally, i created a new container for custom FPC cache name (in this case Punchhole.php) with following content<\/p>\n i also set cache_lifetime to 10 seconds, if you want to make it work well with default FPC, you can set it to 86400 (1 day).<\/p>\n","protected":false},"excerpt":{"rendered":" Magento is slow, it’s a truth . because of its slowness, Magento have some cache mechanisms to make your site faster, so your customers will be happy. Many people choose to use all of caching options available. according to their opinions, the best cache solution for Magento is Full Page Cache (FPC), and it’s one…<\/p>\n\n<block type="core\/text_list" name="top.menu" as="topMenu" translate="label">\n<label>Navigation Bar<\/label>\n<!--<block type="core\/template" template="catalogevent\/lister_navigation.phtml" \/> -->\n<block type="core\/template" name="catalog.event" template="catalogevent\/lister_navigation.phtml" \/>\n<\/block>\n<\/pre>\n
\n<?xml version="1.0" encoding="UTF-8"?>\n<config>\n<placeholders>\n<catalog_navigation>\n<block>core\/template<\/block>\n<name>catalog.event<\/name>\n<placeholder>CATALOG_NAVIGATION_FPC_CUSTOM<\/placeholder>\n<container>Enterprise_PageCache_Model_Container_Catalognavigation<\/container>\n<cache_lifetime>10<\/cache_lifetime>\n<\/catalog_navigation>\n<\/placeholders>\n<\/config>\n\n<\/pre>\n
\n\n<?php\nclass Wage_Fpc_Model_Punchhole extends Enterprise_PageCache_Model_Container_Abstract\n{\n\/**\n* Get customer identifier from cookies\n*\n* @return string\n*\/\nprotected function _getIdentifier()\n{\nreturn $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER, '');\n}\n\n\/**\n* Get cache identifier\n*\n* @return string\n*\/\nprotected function _getCacheId()\n{\nreturn 'CATALOG_NAVIGATION_FPC_CUSTOM' . md5($this->_placeholder->getAttribute('cache_id') . $this->_getIdentifier());\n}\n\n\/**\n* Render block content\n*\n* @return string\n*\/\nprotected function _renderBlock()\n{\n$blockClass = $this->_placeholder->getAttribute('block');\n$template = $this->_placeholder->getAttribute('template');\n\n$block = new $blockClass;\n$block->setTemplate($template);\nreturn $block->toHtml();\n}\n}\n\n<\/pre>\n