PHPackages                             mikk150/yii2-tagdependency-invalidator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. mikk150/yii2-tagdependency-invalidator

ActiveYii2-extension[Caching](/categories/caching)

mikk150/yii2-tagdependency-invalidator
======================================

Invalidates Yii2's TagDependency tags on model update/delete and insert

1.2.0(4y ago)17.8k↓50%1GPL-2.0PHP

Since Dec 28Pushed 4y agoCompare

[ Source](https://github.com/mikk150/yii2-tagdependency-invalidator)[ Packagist](https://packagist.org/packages/mikk150/yii2-tagdependency-invalidator)[ RSS](/packages/mikk150-yii2-tagdependency-invalidator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (5)Used By (0)

Yii2 tagdependency invalidation behavior
========================================

[](#yii2-tagdependency-invalidation-behavior)

[![Build Status](https://camo.githubusercontent.com/3f5b06f03bfb043373671885b25fccb62cfc740ff9002aaeadbb970359f76491/68747470733a2f2f7472617669732d63692e6f72672f6d696b6b3135302f796969322d746167646570656e64656e63792d696e76616c696461746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mikk150/yii2-tagdependency-invalidator)[![codecov](https://camo.githubusercontent.com/1e6024b744526f9e28eda0c50b22664844fb48719c2b8f169e50cd6a73850c2c/68747470733a2f2f636f6465636f762e696f2f67682f6d696b6b3135302f796969322d746167646570656e64656e63792d696e76616c696461746f722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/mikk150/yii2-tagdependency-invalidator)

Usage
-----

[](#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

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 84.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~679 days

Total

3

Last Release

1700d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9ff3e599b4e441314dec7de563477e41e373259653813330c5bfe7874a700018?d=identicon)[mikk150](/maintainers/mikk150)

---

Top Contributors

[![mikk150](https://avatars.githubusercontent.com/u/4953629?v=4)](https://github.com/mikk150 "mikk150 (16 commits)")[![alexeevdv](https://avatars.githubusercontent.com/u/597839?v=4)](https://github.com/alexeevdv "alexeevdv (3 commits)")

---

Tags

cacheyii2extensiontagdependency

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/mikk150-yii2-tagdependency-invalidator/health.svg)

```
[![Health](https://phpackages.com/badges/mikk150-yii2-tagdependency-invalidator/health.svg)](https://phpackages.com/packages/mikk150-yii2-tagdependency-invalidator)
```

###  Alternatives

[undefinedor/yii2-cached-active-record

The cached activeRecord for the Yii2 framework

102.6k](/packages/undefinedor-yii2-cached-active-record)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
