Reputation: 3846
For a while now I've been showing a list of best selling products in my footer, using the code below. However, I just realised that when the cache is enabled, the list doesn't get updated until I refresh the cache. Is there any way around that?
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('name')
->addAttributeToFilter('visibility', $visibility)
->addOrderedQty()
->setOrder('ordered_qty', 'desc')
$_productCollection->load();}
Upvotes: 1
Views: 1124
Reputation: 66
If you check the way the footer block is using the cache in
app/code/core/Mage/Page/Block/Html/Footer.php
you'll notice its cache lifetime is set to indefinite so, putting blocks that are supposed to show dynamic information as child blocks of the footer block is not the best strategy. Instead of disabling or lowering the footer block caching, the better strategy is to consider moving your bestseller block outside of the footer block so that the footer can continue to be cached.
It's better to add a custom block before the footer and use CSS to position your bestsellers where you want them.
Also, a good spot to study how to implement your own block caching is the
app/code/core/Mage/Catalog/Block/Product/New.php
The wiki article linked above is good but somewhat incomplete. Magento provides a special Method to define your cache key getCacheKeyInfo().
Upvotes: 2
Reputation: 10114
You need to look at disabling the cache for the footer block - or at least lowering it's ttl low enough.
There's a good example of how to do this here: http://www.magentocommerce.com/wiki/5_-_modules_and_development/block_cache_and_html_ouput
Upvotes: 1