YII框架页面缓存操作示例 本文实例讲述了YII框架页面缓存操作。分享给大家供大家参考,具体如下: IndexController.php namespace frontend\controllers; use yii; use yii\web\Controller; class IndexController extends Controller { public function behaviors()//先于action执行,可以用来实现页面缓存 { return [ [ 'class'=>'yii\filters\PageCache',//整个页面缓存 'duration'=>10,//缓存时间 'only'=>['cache'],//只有index操作会被缓存,即使没有视图展示也会缓存 'dependency'=>[ 'class'=>'yii\caching\DbDependency', 'sql'=>'select count(*) from user', ], ] ]; } public function actionCache(){ //片段缓存 return $this->renderPartial("index"); } } views/index/index.php 'yii\caching\FileDependency', 'fileName'=>'hw.txt',//web目录下 ]; //缓存的开关 $enabled = false; ?> beginCache('cache_div',['duration' => $duration])){ //if($this->beginCache('cache_div',['enabled' => $enabled])){ if($this->beginCache('cache_div',['dependency' => $dependency])){?>
这里待会会被缓存 哈哈
endCache(); }?>
这里不会被缓存 噜
更多关于Yii相关内容感兴趣的读者可查看本站专题:《Yii框架入门及常用技巧总结》、《php优秀开发框架总结》、《smarty模板入门基础教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》 希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。