Download the PHP package craftcms/yii2-cache-cascade without Composer
On this page you can find all versions of the php package craftcms/yii2-cache-cascade. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package 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
ArrayCacheas a fallback, to prevent your application from crashing while the primary cache (e.g., Redis) is unavailable or restabilizing.
Installation
Usage
Configure the cache component in your Yii2 application config:
Configuration
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
CacheInterfaceinstance
cooldownDuration
The number of seconds a failed cache should be skipped before it is retried. Defaults to 0.
The default retries failed caches on every operation, which matches the original operation-based cascade behavior. For normal web requests, setting this at or above the expected request duration effectively makes failover request-based because the failed cache will not be retried again during that request.
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
| Property | Type | Description |
|---|---|---|
$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
MIT