magento自己带有缓存机制
我们要做的是实现magento的 _construct方法,然后使用addData方法,将里面的cache_lifttime和cache_tags赋值
如下:
在这个例子里,缓存存在的时间为120秒,这个将存在缓存中,知道这个产品的缓存被删除!
-
class {NS } _ {Module }_ Block_ {View } extends Mage_Core_ Block_Template {
-
-
protected function _construct ( )
-
{
-
$this-> addData ( array (
-
'cache_lifetime' => 120,
-
'cache_tags' => array (Mage_Catalog_Model_Product:: CACHE_TAG ),
-
) );
-
}
-
-
}
这个缓存将根据产品id的不同生成不同的缓存
-
class {NS } _ {Module }_ Block_ {View } extends Mage_Core_ Block_Template {
-
-
protected function _construct ( )
-
{
-
$this-> addData ( array (
-
'cache_lifetime' => 120,
-
'cache_tags' => array (Mage_Catalog_Model_Product:: CACHE_TAG ),
-
'cache_key' => $this-> getProduct ( )-> getId ( ),
-
) );
-
}
-
-
}
当我们做缓存的时候,要把要该url下的所有参数加入到cache_key,来保证这个key的唯一性,进而在不同的参数下的页面是不一样的!
我上面是大致写写,如果您想具体的研究,下面是链接地址,可以参看这个
http://www.magentocommerce.com/wiki/5_-_modules_and_development/block_cache_and_html_ouput
或者上谷歌搜索magento block cache
资料也是一大把的,然后就是自己琢磨测试了,一定要保证key的唯一性,不然,很多的不同的页面,做了block cache后发现页面都是第一次访问的那个!
当访问量大的时候,效果还是比较明显的!