-
//获取缓冲组件 $cache=Yii::$app->cache; //缓冲数据写入 $cache->add('key1','Hello1'); //缓冲数据修改 $cache->set('key1','hello2'); //缓冲数据删除 $cache->delete('key1'); //缓冲数据读取 $result=$cache->get('key1'); //清空缓冲数据 $cache->flush('key1');查看全部
-
//页面缓存 public function behaviors(){ echo '1'; return [ [ 'class'=>'yii\filters\PageCache', 'duration'=>1000, 'only'=>['index','test'] 'dependency'=>[ 'class'=>'yii\caching\DbDependency', 'fileName'=>'hw.txt' ] ] ]; } public function actionIndex(){ echo '2'; } public function actionTest(){ echo '2'; }查看全部
-
//片段缓存 前端页面的区域(不经常动的) /* //缓存时间 $duration = 15; if($this->beginCache('cache_div',['duration'=>$duration])){ <div id="cache_div"></div> } $this->endCache(); //缓存依赖 $dependency = [ 'class'=>'yii\caching\FileDependency', 'fileName'=>'hw.txt' ]; if($this->beginCache('cache_div',['dependency'=>$dependency])){ <div id="cache_div"></div> } $this->endCache(); //缓存开关 $enabled = false; if($this->beginCache('cache_div',['enabled'=>$enabled])){ <div id="cache_div"></div> } $this->endCache(); //嵌套缓存 内层时间要比外层时间长 */ //页面缓存 public function behaviors(){ echo '1'; return [ [ 'class'=>'yii\filters\PageCache', 'duration'=>1000, 'only'=>['index','test'] 'dependency'=>[ 'class'=>'yii\caching\DbDependency', 'fileName'=>'hw.txt' ] ] ]; } public function actionIndex(){ echo '2'; } public function actionTest(){ echo '2'; }查看全部
-
//依赖关系 //文件依赖 如果hw.txt发生修改 缓存失效或为false $dependency = new \yii\caching\FileDependency(['fileName'=>'hw.txt']); $cache->add('file_key','hello depend', 3000, $dependency); //表达式依赖 表达式的值发生变化则缓存失效 $dependency = new \yii\caching\ExpressionDependency( ['expression'=>'\YII::$app->request->get("name")'] ); $cache->add('expression_key', 'hello cache', 3000, $dependency); //DB依赖 $dependency = new \yii\caching\DbDependency( ['sql'=>'select count(*) from yii.order'] ) $cache->add('db_key', 'hello cache', 3000, $dependency);查看全部
-
//类懒加载原理 $is_girl = $_GET['girl'] == 0 ? ture : false; if($is_girl){ echo 'this is girl!'; require('class\Class1.php'); $class = new Class1; }else{ echo 'this is not girl!'; require('class\Class2.php'); $class = new Class1; } //yii封装懒加载机制 function my_loader($class){ require('class\\' . $class . '.php'); // require('class\Class2.php'); } spl_autoload_register('my_loader'); $is_girl = $_GET['girl'] == 0 ? ture : false; if($is_girl){ echo 'this is girl!'; $class = new Class1; }else{ echo 'this is not girl!'; $class = new Class1; } //类的映射表 \YII::$classMap['app\models\Order'] = 'D:\www\basic\models\Order.php'; $order = new Order; //组件的延迟加载 哪个方法用在哪加 实质触发__get方法 $session = \YII::$app->session;查看全部
-
页面缓存,与依赖设置查看全部
-
延迟加载类的机制查看全部
-
看看看看看查看全部
-
延迟加载查看全部
-
gii工具查看全部
-
HTTP缓存 例子查看全部
-
HTTPCAche etag查看全部
-
HTTP缓存 filter/HTTPCache查看全部
-
页面缓存查看全部
-
缓存设置 开关查看全部
举报
0/150
提交
取消