Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top