Magento 畅销书列表未在启用缓存的情况下更新
一段时间以来,我一直使用下面的代码在页脚中显示最畅销产品的列表。然而,我刚刚意识到,当启用缓存时,列表不会更新,直到我刷新缓存。有什么办法解决这个问题吗?
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('name')
->addAttributeToFilter('visibility', $visibility)
->addOrderedQty()
->setOrder('ordered_qty', 'desc')
$_productCollection->load();}
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();}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您检查页脚块使用缓存的方式,
您会发现它的缓存生命周期设置为无限期,因此,将应该显示动态信息的块作为页脚块的子块并不是最佳策略。更好的策略是考虑将畅销书块移到页脚块之外,以便继续缓存页脚,而不是禁用或降低页脚块缓存。
最好在页脚之前添加自定义块,并使用 CSS 将畅销书放置在您想要的位置。
另外,研究如何实现自己的块缓存的一个好地方是
上面链接的 wiki 文章很好,但有些不完整。 Magento 提供了一个特殊的方法来定义你的缓存键 getCacheKeyInfo()。
If you check the way the footer block is using the cache in
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
The wiki article linked above is good but somewhat incomplete. Magento provides a special Method to define your cache key getCacheKeyInfo().
您需要考虑禁用页脚块的缓存 - 或者至少将其 ttl 降低到足够低。
这里有一个很好的示例说明如何执行此操作: http://www.magentocommerce.com /wiki/5_-_modules_and_development/block_cache_and_html_ouput
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