且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Magento中缓存集合?

更新时间:2023-11-30 10:10:04

集合已经内置了一些缓存,但是它们需要一些提示,因此请将其放入集合的构造函数中:

Collections already have some caching built in but they need a little prompting so put this in the constructor of a collection:

$cache = Mage::app()->getCacheInstance();
$prefix = "SomeUniqueValue";
$this->initCache($cache, $prefix, array(Mage_Catalog_Model_Product::CACHE_TAG));

选择适合于集合内容的标签,以便将其自动刷新.这种方法基于正在执行的查询来构建ID,当对集合进行过滤,排序或分页时最有用-避免版本冲突.

Choose tags appropriate to the content of the collection so that it will be flushed automatically. This way builds an ID based on the query being executed, it is most useful when the collection is filtered, ordered or paged - it avoids a version conflict.

通常这几乎不被使用,因为当您检索数据时,您几乎总是最终会以HTML形式显示它,因此有意义的是缓存输出.块缓存已得到广泛使用,并得到了更好的记录.

Generally this hardly gets used because when you retrieve data you almost always end up displaying it, probably as HTML, so it makes sense to cache the output instead. Block caching is widely used and better documented.