Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

By best practice collections are typically instantiated in a Block. Best practice also dictates that a Block should set a cache tag and lifetime to take advantage of the Block caching mechanism.

This practice may render the use of a collection cache somewhat useless, at least as far as front-end performance is concerned. However the Collection Cache in Magento is ONLY utilized in TWO areas: neither are guarded by a Block cache: the Website collection (from within Mage::app()) and the Mage_Sales_Model_Resource_Order_Item collection.

This much makes sense. Lots of load on these collections from various places within Magento - it makes sense to implement the cache.

So, my question is: does it ever make sense for me to implement a collection cache if the only place it is used is inside of a Block, and that block does not have wide reuse across the front-end? Any rationale as to best practice here would be welcome.


Typed from my phone, apologies for typos

share|improve this question
    
What about hole-punched blocks with EE FPC? –  Allan MacGregor Jul 20 at 0:15
    
Yeah, Allan, what about them? :) –  philwinkle Jul 20 at 3:58

1 Answer 1

up vote 3 down vote accepted

One scenario I can think of where you might want to cache the collection is if other content within the block is likely to change or you're working with multiple collection models.

For instance: Say you need to list the catalog's categories but mark ones where the customer has purchased something within those categories.

The list of categories will be same for all customers but the output would be different for each customer.

In this case it would make sense to cache the collection but not the block.

Another example: If you were to list categories and had a custom blog post model which are associated to a category. In this case you may want to cache the category collection since it doesn't change much but not the related blog collections as they'll be more likely to change. You can still cache the block for a set amount of time (e.g. a few hours) but cache the collection for a longer period of time (a few days).

I would imagine these types of cases are not very common tho.

share|improve this answer
    
I really like this rationale. It's a shame it isn't used more often because it could possibly help larger custom builds with sprawling catalogs. Unlike the Block Cache the Collection Cache never expires so it has at least a small benefit for those loads that happen to have expired the block cache. –  philwinkle Jul 21 at 3:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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