PHPackages                             hyperia/yii2-clear-cache-behavior - 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. hyperia/yii2-clear-cache-behavior

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

hyperia/yii2-clear-cache-behavior
=================================

The behavior for Yii2 to clearing cache on specific events

v2.0.0(5y ago)04.0k↓50%1[1 issues](https://github.com/hyperia-sk/yii2-clear-cache-behavior/issues)MITPHPPHP &gt;=7.1

Since Jul 31Pushed 5y ago3 watchersCompare

[ Source](https://github.com/hyperia-sk/yii2-clear-cache-behavior)[ Packagist](https://packagist.org/packages/hyperia/yii2-clear-cache-behavior)[ RSS](/packages/hyperia-yii2-clear-cache-behavior/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Yii2 clear cache behavior
=========================

[](#yii2-clear-cache-behavior)

[![GitHub license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/hyperia-sk/yii2-clear-cache-behavior/master/LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/036781dd707b679a87712b78e34718b8a7ee17573e2daff2fe0b24d46b574bc5/68747470733a2f2f706f7365722e707567782e6f72672f687970657269612f796969322d636c6561722d63616368652d6265686176696f722f762f737461626c65)](https://packagist.org/packages/hyperia/yii2-clear-cache-behavior)

> The behavior for Yii2 to clearing cache on specific events

Instalation
-----------

[](#instalation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require hyperia/yii2-clear-cache-behavior:"*"
```

or add

```
"hyperia/yii2-clear-cache-behavior": "*"

```

to the require section of your composer.json.

Configuration (usage)
---------------------

[](#configuration-usage)

In ActiveRecord Model class to invalidate tag after insert, update or delete

```
use yii\db\ActiveRecord;
use hyperia\behaviors\ClearCacheBehavior;

class Model extends ActiveRecord
{
    private const CACHE_KEY = '~model~';

    public function behaviors()
    {
        return [
            ...
            'clearCache' => [
                'class' => ClearCacheBehavior::class,
                'events' => [
                    ActiveRecord::EVENT_AFTER_INSERT,
                    ActiveRecord::EVENT_AFTER_UPDATE,
                    ActiveRecord::EVENT_AFTER_DELETE
                ],
                'type' => ClearCacheBehavior::TYPE_INVALIDATE_TAG,
                'value' => static::CACHE_KEY
            ],
        ];
    }
}
```

Parameter description
---------------------

[](#parameter-description)

### events

[](#events)

*array*

Determinantes on which event would be cache deleted. When you want set up Event with same settings.

Default value:

```
[
    ActiveRecord::EVENT_AFTER_INSERT,
    ActiveRecord::EVENT_AFTER_UPDATE,
    ActiveRecord::EVENT_AFTER_DELETE
]

```

### cache

[](#cache)

*string*

Name of cache component in yii components configuration
**Default: "cache"**

### value

[](#value)

*string | array | Closure*
Determinantes which part of cache would be deleted **ONLY WHEN EVENTS IS SET**

### type

[](#type)

*string*
Sets how the cache will be deleted **ONLY WHEN EVENTS IS SET**
Types:

- TYPE\_INVALIDATE\_TAG : Calls yii\\caching\\TagDependency::invalidate($cacheObject, $value);
- TYPE\_FLUSH : Calls flush() method on cache object (by value of cache parameter)
- TYPE\_DELETE : Calls delete($value) method on cache object (by value of cache parameter)

### events\_with\_settings

[](#events_with_settings)

*array*
Array which represents setting of multiple events. Determinantes on which event would be cache deleted. When you want set up multiple Events

Simple example:

```
    'eventsWithSettings' => [
          \yii\web\Controller::EVENT_BEFORE_ACTION => [
              'type' => ClearCacheBehavior::TYPE_INVALIDATE_TAG,
              'value' => static::CACHE_KEY
          ],
          \yii\web\Controller::EVENT_AFTER_ACTION => [
              'type' => ClearCacheBehavior::TYPE_DELETE,
              'value' => function($event) use ($model) {
                  return $model->id;
              }
          ]
    ],
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~88 days

Total

2

Last Release

2029d ago

Major Versions

v1.0.0 → v2.0.02020-10-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/9861d8483a334bd54621b1829f2b55620417df08080a0fe29426659eacb9385b?d=identicon)[karster](/maintainers/karster)

---

Top Contributors

[![janki1](https://avatars.githubusercontent.com/u/2636233?v=4)](https://github.com/janki1 "janki1 (4 commits)")

---

Tags

behaviorcacheyii2yii2-behaviorscacheyii2extensionBehavior

### Embed Badge

![Health badge](/badges/hyperia-yii2-clear-cache-behavior/health.svg)

```
[![Health](https://phpackages.com/badges/hyperia-yii2-clear-cache-behavior/health.svg)](https://phpackages.com/packages/hyperia-yii2-clear-cache-behavior)
```

###  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)
