Full Page Cache Bolt Full Page Cache

Hole Punch Dynamic Blocks with Bolt

The more that can be cached on a page, the faster it will be. Unfortunately it's not always possible to cache the whole page as certain sections are completely dynamic and unique to each user. To get around this, Bolt uses a hole punching system.

What is Hole Punching?

Hole punching is a system that allows you to mark certain sections of a page to be loaded each time and never cached while still caching the rest of the page. Bolt will load a page from the cache and then fill in the holes with dynamic content. In Magento, the most common block to be hole punched is the header, as this usually contains dynamic content such as a shopping cart summary and different links depending on whether the customer is logged in or not. As this is such a commonly hole punched block, Bolt will hole punch this block automatically so you don't need to add this to the hole punch list.

Default Hole Punch Configuration

By default, Bolt will automatically hole puncht the 'header' block. For 90% of Magento installtions, this is the only block that will need hole punching, which means that you don't need to make any changes to the hole punch configuration. If you do need to add a new block to the hole punch, keep reading.

Add a Block to the Hole Punch

To add a new block to the hole punch, login to the Magento Admin and select System > Configuration > Bolt and then find the Hole Punch section. After making any changes to the hole punch you will need to flush the Bolt cache for these changes to take affect.

Click the 'Add New' button to create a new row for the Hole Punch. You should see 2 fields: Block Name and Punch a Hole.

Block Name

The Block Name fields expect the name of the block that you want to hole punch. This name is the name of the block in your XML layout. If you are unsure of what this is, there is an easy way to find out. Find the template that the block uses (if you aren't sure which template, enable Template Path Hints in System > Developer > Template Path Hints. You will need to change to the store scope to see this configuration option) and open that template using FTP. Inside th template, add the following code to the top:

<?php echo 'Block Name: ' . $this->getNameInLayout(); exit; ?>

This code will write out the name of the block in the XML layout. This is the exact value that you need to use for the 'Block Name' field in the configuration.

Punch a Hole

The punch a hole field allows you to configure when a block should be hole punched and when it should be loaded from the cache. There are 4 options for this field.

Always

This option will trigger Bolt to always hole punch the block and load it dynamically. Bolt will never load the block from the cache.

When items are in the cart

This option will trigger Bolt to load the block from the cache until the customer adds a product to their cart, at which point the block will be loaded dynamically. If the customer removes all products from their cart, Bolt will load the block from the cache.

When the customer is logged in

This option will trigger Bolt to load the block from the cache until the customer logs in to their account, at which point the block will be loaded dynamically. If the customer logs out, the block will be loaded from the cache.

When items are in the cart or the customer is logged in

This option will trigger Bolt to load the block from the cache until either the customer logs in to their account or the customer adds a product to their shopping cart. If the customer logs out of their account and removes all products from their shopping cart, the block will be loaded from the cache again.

Hole Punch Cache

To make the hole punch even faster, Bolt uses a caching system on the hole punch. If you have any problems with the Hole Punch and find that incorrect content is displaying, try disabling this feature (System > Configuration > Bolt > Hole Punch > Cache).

Post your comment

FishPig Ltd