zoukankan      html  css  js  c++  java
  • YII页面缓存

    IndexController.php

    namespace frontendcontrollers;
    use yii;
    use yiiwebController;
    
    class IndexController extends Controller
    {
        public function behaviors()//先于action执行,可以用来实现页面缓存
        {
            return [
              [
                  'class'=>'yiifiltersPageCache',//整个页面缓存
                  'duration'=>10,//缓存时间
                  'only'=>['cache'],//只有index操作会被缓存,即使没有视图展示也会缓存
                  'dependency'=>[
                      'class'=>'yiicachingDbDependency',
                      'sql'=>'select count(*) from user',
                  ],
              ]
            ];
        }
        public function actionCache(){
            //片段缓存
            return $this->renderPartial("index");
        }
    }

    views/index/index.php

    <?php
    /**
     * Created by PhpStorm.
     * Date: 2016/5/25
     * Time: 19:37
     */
    
    $duration = 15;
    
    //缓存依赖
        $dependency = [
            'class'=>'yiicachingFileDependency',
            'fileName'=>'hw.txt',//web目录下
        ];
    
    //缓存的开关
    $enabled = false;
    ?>
    <?php
       //if($this->beginCache('cache_div',['duration' => $duration])){
        //if($this->beginCache('cache_div',['enabled' => $enabled])){
       if($this->beginCache('cache_div',['dependency' => $dependency])){?>
           <div id="cache_div">
               <div>这里待会会被缓存 哈哈</div>
           </div>
    <?php
       $this->endCache();
    }?>
    <div id="no_cache_div">
        <div>这里不会被缓存 噜</div>
    </div>
  • 相关阅读:
    Python中把数据存入csv文件
    Python中把字典和值取出来
    scrapy输出请求状态码
    scrapy发送post请求获取cookie
    Python3 Unicode转中文
    Quartus13.0破解方法
    元音字母A的发音规则
    位bit——字节Byte???
    曾经的小孩在努力奔跑!
    如何看懂的时序图?
  • 原文地址:https://www.cnblogs.com/isuben/p/5529814.html
Copyright © 2011-2022 走看看