yii 片断缓存beginCache

yii 片段缓存beginCache

用法:

 

 

...别的HTML内容...
<?php if($this->beginCache($id)) { ?>
...被缓存的内容...
<?php $this->endCache(); } ?>
...别的HTML内容...

 

...其他HTML内容...
<?php if($this->beginCache($id, array('duration'=>3600))) { ?>
...被缓存的内容...
<?php $this->endCache(); } ?>
...其他HTML内容...
 

 

  说明:

 

1,在上面的,如果beginCache() 返回false,缓存的内容将此地方自动插入; 否则,在if语句内的内容将被执行并在endCache()触发时缓存。

2,如果我们不设定期限,它将默认为60 ,这意味着60秒后缓存内容将无效。

 

有前缓存其他参数设置及嵌套缓存请看:

http://www.yiiframework.com/doc/guide/1.1/zh_cn/caching.fragment#sec-2