时间:2021-07-01 10:21:17 帮助过:11人阅读
3、设置数据库缓存依赖:
// 所有表model继承的基础BaseModel.php
/** * @name 获取缓存数据库依赖 * @author testMe * @date 2016-12-06 * @param array $params 缓存依赖参数 * @example * 1.请检查使用model对应表是否有update_time字段 * 2.对应使用model请继承BaseModel * 3.调用BaseModel的getCacheDbDependency()方法 */ public static function getCacheDbDependency($params = []) { // 缓存依赖sql $dbDependencySql = self::find()->select(‘max(update_time)‘) ->where(‘deleted=0‘) ->createCommand() ->sql; // 设置缓存依赖 $dbDependency = new DbDependency(); $dbDependency->db = Yii::$app->components[‘db‘]; $dbDependency->sql = $dbDependencySql; $dbDependency->params = $params; return $dbDependency; }
4、发布缓存时使用:
// 获取缓存依赖 $dbDependency = SysCodeDetail::getCacheDbDependency(); $cache = Yii::$app->cache; // 更新缓存文件 $result = $cache->set(‘SysCodeEnum‘, SysCode::$_enum, 0, $dbDependency); if (!$result) { return false; }
Yii2.0数据库缓存依赖发布的使用理解
标签:生成 end attr name and png component turn http