mikk150/yii2-tagdependency-invalidator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Build Status codecov

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

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2017-12-28