mikk150/yii2-tagdependency-invalidator
最新稳定版本:1.2.0
Composer 安装命令:
composer require mikk150/yii2-tagdependency-invalidator
包简介
Invalidates Yii2's TagDependency tags on model update/delete and insert
README 文档
README
Usage
To use this behavior, add it to model's or components behaviors model
class Book extends yii\base\ActiveRecord { const CACHE_KEY = 'BOOKS_ARE_AWESOME!'; public function behaviors() { return [ [ 'class' => 'mikk150\tagdependency\InvalidateBehavior', 'tags' => [ [ self::CACHE_KEY, 'id' => 'primaryKey', ], ] ] ] } }
then where you want to use cached models, just do this
public function actionView($id) { return Yii::$app->cache->getOrSet(['book', $id], function () use ($id) { return Book::find()->byId($id)->one(); }, null, new TagDependency([ 'tags' => [ [ Book::CACHE_KEY, 'id' => $id, ] ] ])) }
if BaseActiveRecord::EVENT_AFTER_UPDATE, BaseActiveRecord::EVENT_AFTER_INSERT or BaseActiveRecord::EVENT_AFTER_DELETE is triggered, then cache is automatically invalidated for this model based on key rules
additionally, you can also clear cache by executing invalidate() on model1
统计信息
- 总下载量: 7.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2017-12-28