页面缓存

 1 <?php
 2 namespace app\controllers;
 3 use yii\web\Controller;
 4 
 5 
 6 class HelloController extends Controller {
 7     public function behaviors() {
 8         return[
 9             [
10                 'class'=>'yii\filters\PageCache', //页面缓存
11                 'duration'=>1000,//缓存时间
12                 'only'=>['index','test'], //缓存的页面
13                 'dependency'=>[     //缓存依赖
14                     'class'=>'yii\caching\FileDependency',
15                     'fileName'=>'hw.txt'
16                 ]
17             ]
18         ];
19     }
20     public function actionIndex()
21     {
22       echo '5';
23 //        return $this->render('index');
24     }
25     public function actionTest() {
26         echo '4';
27     }
28 }

其中 behaviors() 方法会优先于其它的function

posted @ 2015-08-26 16:29  todaytoday  阅读(189)  评论(0)    收藏  举报