Yii2 缓存
来源:互联网 发布:女装淘宝首页 编辑:程序博客网 时间:2024/06/05 17:27
参考:http://www.yiiframework.com/doc-2.0/guide-caching-overview.html
配置
'components' => ['cache' => [ 'class' => 'yii\caching\FileCache', ],
数据缓存
$cache = \Yii::$app->cache;$cache['aa'] = '123';echo $cache['aa'];
片段缓存
<h1>朝代</h1><?php if($this->beginCache($id, ['duration' => 3600])) { ?><?phpecho ListView::widget(['dataProvider' => $dataProvider,'itemView' => '_item',]);?><?php $this->endCache(); } ?>$dependency = [ 'class' => 'yii\caching\DbDependency', 'sql' => 'SELECT MAX(updated_at) FROM post',];if ($this->beginCache($id, ['dependency' => $dependency])) { // ... generate content here ... $this->endCache();}if ($this->beginCache($id, ['variations' => [Yii::$app->language]])) { // ... generate content here ... $this->endCache();}if ($this->beginCache($id1)) { // ...content generation logic... if ($this->beginCache($id2, $options2)) { // ...content generation logic... $this->endCache(); } // ...content generation logic... $this->endCache();}
页面缓存
class TestController extends Controller{ public function actionIndex() {//$db = \Yii::$app->db;sleep(2);$query = Dynasty::find();$dataProvider = new ActiveDataProvider(['query' => $query,'pagination' => ['pageSize' => 15,],]);return $this->render('index', [ 'dataProvider' => $dataProvider ]); }public function behaviors(){return [['class' => 'yii\filters\PageCache','duration' => 60, 'variations'=> [$_GET['page']],],];}}
动态内容
...别的HTML内容...<?php if($this->beginCache($id)) { ?>...被缓存的片段内容... <?php $this->renderDynamic($callback); ?>...被缓存的片段内容...<?php $this->endCache(); } ?>...别的HTML内容...
1 0
- Yii2 缓存
- YII2缓存
- yii2.0缓存介质
- Yii2数据缓存详解
- Yii2片段缓存详解
- Yii2页面缓存详解
- Yii2详解HTTP缓存
- yii2使用缓存
- Yii2-类图-缓存
- Yii2片段缓存详解
- yii2页面缓存
- yii2设置缓存
- yii2从命令行删除缓存
- yii2.0的http缓存
- yii2.0缓存篇之片段缓存
- yii2.0缓存篇之文件缓存
- yii2.0缓存篇之页面缓存
- yii2缓存的介绍和使用
- minicom配置及使用方法
- TCON控制字及TMOD寄存器
- HTTP请求(请求头、响应头)详解(一)
- Eclipse使用Maven创建Web时错误:Could not resolve archetype org.apache.maven.archetypes:maven-archetype-weba
- 准备篇:系统环境设置
- Yii2 缓存
- Android项目学习—Intent的作用详解
- 利用C#的反射机制动态调用DLL类库
- 数据结构之二叉树(遍历、建立、深度)
- 1071. Speech Patterns
- 两会背景下的主题投资基金
- find和find_if
- Machine Learning SVM
- 5.PMAC下位机-下位机编程基础