herroffizier/yii2-ar-tag-cache

Yii 2 component for automatic cache invalidation invoked by ActiveRecord updates.

Installs: 901

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Type:yii2-extension

1.0.0 2016-04-09 10:44 UTC

This package is not auto-updated.

Last update: 2024-11-15 19:50:27 UTC


README

Build Status Scrutinizer Code Quality Code Coverage

Yii2 AR Tag Cache automatically invalidates tagged cache when ActiveRecord changes.

In fact it is a simple wrapper over Yii2's TagDependency. It creates special tag for ActiveRecord class and invalidates all cache marked by that tag when any of that class instances is being created, updated or deleted.

Installation

Install extension with Composer:

composer require "herroffizier/yii2-ar-tag-cache:@stable"

Attach behavior to AR model:

public function behaviors()
{
    return [
        'arCache' => [
            'class' => \herroffizier\yii2artc\Behavior::className(),
        ],
    ];
}

Usage

// Get tag dependency:
$dependency = $model->tagDependency;

// Attach dependency to cache:
Yii::$app->cache->set('cache', 'test', 0, $dependency);

// Now if you call save() or delete() for any instance of $model's class, cache will be invalidated.
// Also you may force cache invalidation without modifying models:
$model->invalidateCache();