DB依赖, 数据缓存
$cache->set('CategoryCache', Category::CategoryList(),3600 * 24 * 365, new DbDependency(['sql' => "SELECT `TABLE_NAME`, `UPDATE_TIME` FROM `information_schema`.`TABLES` WHERE `information_schema`.`TABLES`.`TABLE_SCHEMA` = 'shop' AND`information_schema`.`TABLES`.`TABLE_NAME` = 'category'"]));
var_dump($cache['CategoryCache']);
DB依赖, 查询缓存
$cat = Category::getDb()->cache(function()use($id, $key){
return Category::find()->where(['id' => $id])->asArray()->all();
}, 3600 * 24 * 365, new DbDependency(['sql' => "SELECT `TABLE_NAME`, `UPDATE_TIME` FROM `information_schema`.`TABLES` WHERE `information_schema`.`TABLES`.`TABLE_SCHEMA` = 'shop' AND `information_schema`.`TABLES`.`TABLE_NAME` = 'category'"]));
<?php
if($this->beginCache("cache_div54", [
'duration' => 3600 * 3600 * 3600,
'dependency' => [
'class' => yii\caching\DbDependency::className(),
'sql' => "SELECT `TABLE_NAME`, `UPDATE_TIME` FROM `information_schema`.`TABLES` WHERE `information_schema`.`TABLES`.`TABLE_SCHEMA` = 'shop' AND `information_schema`.`TABLES`.`TABLE_NAME` = 'category'",
],
])):
?>
<h1>someOne</h1>
<?php $this->endCache();
endif;
\YII::$app->end();?>
片段缓存依赖
缓存依赖
最新推荐文章于 2019-08-09 18:44:04 发布