How to exclude block from caching by Full Page Cache?
Using hole-punching feature guide.
Posted on 19 December 2016
Our Full Page Cache extension works great for default Magento pages and functionality. However, there is often a necessity to make a compatibility with some 3rd-party module.
Sometimes, it may be necessary to exclude some blocks from caching. With FPC API, you can give instructions to provide this hole-punching functionality.
The description of the main config file: app/code/community/Potato/FullPageCache/etc/po_fpc.xml
top.links Potato_FullPageCache_Model_Processor_Block_Session_Nocache Potato_FullPageCache_Model_Processor_Block_Session_Cart Potato_FullPageCache_Model_Processor_Block_Session_Messages Potato_FullPageCache_Model_Processor_Block_Session_Messages catalog.compare.sidebar Potato_FullPageCache_Model_Processor_Block_Session_Compare Potato_FullPageCache_Model_Processor_Block_Dynamic_Countdown view view po_fpc/processor_router_catalog 2592000 * * 2592000
It consists of the 2 main sections:
- session_blocks contains the description of the blocks which has unique content for users. Each block must be in unique node and can contain 3 subsidiary node
name_in_layout is a unique name of the block on the page
processor is a name of class (related to block updating)
lifetime is the lifetime of the block cache
- allowed_routers contains the description of the controllers allowed for caching
When it is necessary to exclude some specific blocks from caching, it is needed to create app/code/community/Potato/FullPageCache/etc/custom.xml file with required instructions. Note, the structure of this file must be followed.
Some general use-cases:
To exclude a block which contains customer data:
To limit the cache lifetime of a block on the homepage:
To exclude a price block on product\category pages or any other block which does not have a unique name:
It is necessary to create app/code/community/Potato/FullPageCache/Model/Processor/Block/Dynamic/Custom.php file. You can use app/code/community/Potato/FullPageCache/Model/Processor/Block/Dynamic/Countdown.php as an example
To exclude a block with a unique name on product\category pages:
po_fpc/processor_router_catalog 2592000 custom_block Potato_FullPageCache_Model_Processor_Block_Action_Nocache
To exclude a block on product\category pages which is called in a template, for example,
po_fpc/processor_router_catalog 2592000 custom_block Potato_FullPageCache_Model_Processor_Block_Action_Nocache mage/customtemplate.phtml 1 N
To add a custom controller::
* * 2592000
How to identify the block name on the page?
1. enable all the option in the System->Configuration->Developer->Debug section in the extension settings:
2. go to a certain page and check the name of a required block. The block with ANONYMOUS_ prefix means that the block has a temporary name.