I have implemented hole-punching of header in Magento, and even though I have got it working on a per-customer basis, I need the ability to take this one level deeper by making it work on diff cart items counts too.

Here is my code.

    class AD_PageCache_Model_Container_Header extends Enterprise_PageCache_Model_Container_Abstract {

    protected function _getIdentifier() {
        return $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER, '');

    // public function getCacheKeyInfo() {
    //  $info = parent::getCacheKeyInfo();
    //  die('boo');
    //  $info['cart_count'] = Mage::helper( 'checkout/cart' )->getCart()->getItemsCount();

    //  return $info;
    // }

    protected function _getCacheId() {
        //return 'CONTAINER_HEADER_' . md5($this->_placeholder->getAttribute('cache_id') . $this->_placeholder->getAttribute('cart_count') ) . '_' . $this->_getIdentifier();
        return 'CONTAINER_HEADER_' . md5( $this->_placeholder->getAttribute('cache_id') . $this->_getIdentifier() );

    protected function _renderBlock() {
        $blockClass = $this->_placeholder->getAttribute('block');
        $template = $this->_placeholder->getAttribute('template');

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


My understanding from what I have been reading from hole-punching threads on Magento is that the Mage app is not initialized when the FPC cache is serving the request, so basically, the method of adding a placeholder attribute can't work, since

Mage::helper( 'checkout/cart' )->getCart()->getItemsCount();

won't work, right?

And even though how is that it should be, but it didn't seem to run at all like I placed a die() call in there but nothing happened.

So what I am missing? And how can I retrieve the cart items count so that it can be used to build the cache ID?

Progress: I found


but this changes only once upon cart updation. After that, it stays the same. This is weird, this feels like the solution but its behavior says otherwise.

I couldn't find cart items count in session either. So the only way I currently see to do this would be to save the cart quantity in session whenever it updates and then uses that in _getIdentifier().

I found that observers are inconsistent with the cart. In addition, updation the events are dispatched but for removal, it doesn't. So I guess I can add my observer to price updation of the quote somehow if that is consistent in having observers?

Also, I did read Full Page Cache invalidation on the cart (quote) change but it handles using


which doesn't work well in my case, although I think the problem lies inside it. What/How? I am not sure.

Also the current version of EE we have running doesn't even have Advanced folder under Model/Container. I am using EE

Any suggestions?

  • Not sure, but I think that this question is more related to Stack Overflow, but not this site...
    – Sergei Guk
    Commented Jan 22, 2013 at 22:27
  • 2
    Holepunching seems to be used here in a non traditional sense, can you explain the feature you're trying to implement without using jargon?
    – Ralph Tice
    Commented Jan 22, 2013 at 22:40
  • 1
    Why not append the customers cart id to _getIdentifier so the block is unique to customers cart, or even the number of items in their cart?
    – B00MER
    Commented Jan 23, 2013 at 19:59
  • @SergeiGuk Well it's heavily related to Magento
    – j0k
    Commented Jan 25, 2013 at 10:24
  • @RalphTice I'm trying to implement a cart value indicator in the header which shows the user how many items they have in their cart. Since that value is different per user, I don't want it to be cached. Commented Jan 27, 2013 at 16:38

1 Answer 1


Using Enterprise_PageCache_Model_Cookie::COOKIE_CART is the right way to go, but you may need to do some changes.

Enterprise_PageCache_Model_Observer::registerQuoteChange is called on every quote save (item number change included) and it is also called in the context on Mage::app() so you can access all session data. Overwrite this observer and add more data in $this->_getCookie()->setObscure so the value changes whenever you need to.

  • Any examples you might be willing to share on doing this? Commented Feb 4, 2013 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.