PHPackages                             pahanini/yii2-neat-cache - 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. pahanini/yii2-neat-cache

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

pahanini/yii2-neat-cache
========================

A Yii2 components to prevent simultaneous updates (dog pile effect) during caching.

v0.0.4(9y ago)67.3k↑37.1%3BSD-3-ClausePHPPHP &gt;=5.4.0

Since Nov 5Pushed 9y ago1 watchersCompare

[ Source](https://github.com/pahanini/yii2-neat-cache)[ Packagist](https://packagist.org/packages/pahanini/yii2-neat-cache)[ Docs](https://github.com/pahanini/yii2-neat-cache)[ RSS](/packages/pahanini-yii2-neat-cache/feed)WikiDiscussions master Synced 2d ago

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

\#Yii2 Neat cache

[![Build Status](https://camo.githubusercontent.com/3c601e38f1d82f0bfadb156cbe23352bf4b2c1c2ffadce9726c586fe1c445986/68747470733a2f2f7472617669732d63692e6f72672f706168616e696e692f796969322d6e6561742d63616368652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/pahanini/yii2-neat-cache)[![Latest Stable Version](https://camo.githubusercontent.com/c611b6625ad12c1d65abd913895f4fcc1e505b84ec43751da007f76338f39087/68747470733a2f2f706f7365722e707567782e6f72672f706168616e696e692f796969322d6e6561742d63616368652f762f737461626c65)](https://packagist.org/packages/pahanini/yii2-neat-cache)[![Total Downloads](https://camo.githubusercontent.com/a798ef1fb577b6739c8e6bc2ca28d4505bde462ea8d76d9b3e4ae3585d0c81f1/68747470733a2f2f706f7365722e707567782e6f72672f706168616e696e692f796969322d6e6561742d63616368652f646f776e6c6f616473)](https://packagist.org/packages/pahanini/yii2-neat-cache)[![Latest Unstable Version](https://camo.githubusercontent.com/afb6c66e9e4ad3b43cd79c0035a212bb0e78772b76de00363f937b37716a002b/68747470733a2f2f706f7365722e707567782e6f72672f706168616e696e692f796969322d6e6561742d63616368652f762f756e737461626c65)](https://packagist.org/packages/pahanini/yii2-neat-cache)[![License](https://camo.githubusercontent.com/86578c3ae741ffd7c11c6c4e39d2b890345f9d520a99931dd85fcebbc004bc12/68747470733a2f2f706f7365722e707567782e6f72672f706168616e696e692f796969322d6e6561742d63616368652f6c6963656e7365)](https://packagist.org/packages/pahanini/yii2-neat-cache)

About
-----

[](#about)

Improved Yii2 [PageCache](http://www.yiiframework.com/doc-2.0/yii-filters-pagecache.html)filter to prevent dog-pile effect in yii2 applications. Please see for more information about dog-pile effect.

Install
-------

[](#install)

- Add `"pahanini/yii2-neat-cache": "*"` to required section of your composer.json

Usage
-----

[](#usage)

There are two main components MutexDependency and PageCache. Both require mutex component of your application.

```
'components' => [
	'mutex' => [
		'class' => 'tests\components\MysqlMutex',
	]
]
```

### MutexDependency

[](#mutexdependency)

For example you need prevent simultaneous calls of heavy function. Even if the function result is cached at the moment cache expired there is a chance that two apache workers will call this function twice or even worse.

First step to prevent this behavior is to prepare chained dependency with dependOnAll property set to false. Use first sub dependency to manage data expiration. Second dependency is MutexDependency.

```
$dependency = Yii::createObject([
	'class' => '\yii\caching\ChainedDependency',
	'dependOnAll' => false,
	'dependencies' => [
		Yii::createObject([
			'class' => '\yii\caching\ExpressionDependency',
			'expression' => 'Helper::isTimeToUpdate()',
		]),
		Yii::createObject([
			'class' => '\pahanini\neatcache\MutexDependency',
			'tag' => 'HeavyFunction',
		]),
	]
]);
```

If first dependency has changed for the first time then second one tries to acquire mutex lock and in case of success is considered to be changed and make cache invalid (both dependencies were changed).

Second step is to use created dependency with never expired duration value to set cache data

```
	if (!$data = Yii::$app->cache->get('heavyDataId')) {
		Yii::$app->cache->set('heavyDataId', heavyFunctionCall(), 0, $dependency);
	}
```

### PageCache filter

[](#pagecache-filter)

Replace native yii2 PageCache filter neat one and make cache never expired. Everlasting cache allows neat PageCache filter to use old data from expired cache to prevent dog pile effect. To make page expired you should use any of cache dependencies.

```
return [
	'pageCache' => [
		'class' => '\pahanini\neatcache\PageCache',
		'only' => ['index'],
		'duration' => 0,
		'dependency' => [
			'class' => 'yii\caching\ExpressionDependency',
			'expression' => '\tests\NeatCacheTest::$tag',
		],
	],
];
```

Neat PageCache automatically creates chained dependency based on specified one to prevent dog pile effect during page caching.

Testing
-------

[](#testing)

Copy tests config `main-local.php.sample` to `main-local.php` and run

```
$ phpunit
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The BSD License.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.8% 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 ~163 days

Total

4

Last Release

3403d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b2ff5824ce711862778444b44442b7ae3b4aa7f1804a29da2c5ad375aecb5448?d=identicon)[pahanini](/maintainers/pahanini)

---

Top Contributors

[![pahanini](https://avatars.githubusercontent.com/u/898663?v=4)](https://github.com/pahanini "pahanini (23 commits)")[![pastuhov](https://avatars.githubusercontent.com/u/7937221?v=4)](https://github.com/pastuhov "pastuhov (1 commits)")

---

Tags

mutexcacheyii2doc pilesimultaneous updates

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pahanini-yii2-neat-cache/health.svg)

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[devgroup/yii2-tag-dependency-helper

Helper for unifying cache tag names with invalidation support in yii2

34530.0k7](/packages/devgroup-yii2-tag-dependency-helper)[undefinedor/yii2-cached-active-record

The cached activeRecord for the Yii2 framework

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

PHPackages © 2026

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