PHPackages                             craftcms/yii2-cache-cascade - 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. craftcms/yii2-cache-cascade

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

craftcms/yii2-cache-cascade
===========================

A Yii2 cache component that cascades through multiple cache drivers on failure

1.2.1(1mo ago)01.5k↑91.9%2MITPHPPHP &gt;=7.4

Since Jan 15Pushed 2mo agoCompare

[ Source](https://github.com/craftcms/yii2-cache-cascade)[ Packagist](https://packagist.org/packages/craftcms/yii2-cache-cascade)[ RSS](/packages/craftcms-yii2-cache-cascade/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (2)Dependencies (8)Versions (8)Used By (2)

Yii2 Cache Cascade
==================

[](#yii2-cache-cascade)

A Yii2 cache component that cascades through multiple cache drivers on failure, preventing app downtime due to cache outages.

> **Note:** This is not a multi-store/write-through cache. Only one cache component is used at a time. This makes the most sense when using a fast, in-memory cache like `ArrayCache` as a fallback, to prevent your application from crashing while the primary cache (e.g., Redis) is unavailable or restabilizing.

Installation
------------

[](#installation)

```
composer require craftcms/yii2-cache-cascade
```

Usage
-----

[](#usage)

Configure the cache component in your Yii2 application config:

```
use craft\cachecascade\CascadeCache;
use craft\cachecascade\CacheFailedEvent;

'components' => [
    'cache' => [
        'class' => CascadeCache::class,
        'caches' => [
            'redisCache',
            [
                'class' => \yii\caching\ArrayCache::class,
            ],
        ],
        'on cacheFailed' => function (CacheFailedEvent $event) {
            // Custom logging
            Yii::error(
                "Cache failover: {$event->operation} failed on " . get_class($event->cache) . ': ' . $event->exception->getMessage(),
                'cache'
            );

            // Or send to external monitoring
            // MyMonitoring::trackCacheFailure(get_class($event->cache), $event->exception);

            // Optionally prevent cascading (will re-throw the exception)
            // $event->shouldCascade = false;
        },
    ],
    'redisCache' => [
        'class' => \yii\redis\Cache::class,
        'redis' => [
            'hostname' => 'localhost',
            'port' => 6379,
            'connectionTimeout' => 1,
            'dataTimeout' => 1,
            'retries' => 1,
            'retryInterval' => 0,
        ],
    ],
],
```

Configuration
-------------

[](#configuration)

### `caches`

[](#caches)

An array of cache components in priority order. Each element can be:

- **String**: A component ID (e.g., `'redis'`, `'cache'`)
- **Array**: A Yii2 component configuration
- **Object**: A `CacheInterface` instance

Events
------

[](#events)

The component triggers a `CascadeCache::EVENT_CACHE_FAILED` event when a cache operation fails (shown in the usage example above). Use this for custom logging, monitoring, or to control cascade behavior.

### `CacheFailedEvent` Properties

[](#cachefailedevent-properties)

PropertyTypeDescription`$cache``CacheInterface`The cache that failed`$operation``string`The operation that failed (`'get'`, `'set'`, etc.)`$exception``\Throwable`The exception that was thrown`$shouldCascade``bool`Whether to cascade to the next cache (default: `true`)License
-------

[](#license)

MIT

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance87

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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 ~11 days

Total

7

Last Release

54d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ccdf8b493035de2343c55bd889513e3af5c04d5823482a2b186ad16adb1c3e3?d=identicon)[brandonkelly](/maintainers/brandonkelly)

---

Top Contributors

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

---

Tags

cacheyii2fallbackcascaderesilience

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/craftcms-yii2-cache-cascade/health.svg)

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

###  Alternatives

[devgroup/yii2-tag-dependency-helper

Helper for unifying cache tag names with invalidation support in yii2

34507.4k7](/packages/devgroup-yii2-tag-dependency-helper)[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)
