PHP code example of craftcms / yii2-cache-cascade
1. Go to this page and download the library: Download craftcms/yii2-cache-cascade library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
craftcms / yii2-cache-cascade example snippets
use craft\cachecascade\CascadeCache;
use craft\cachecascade\CacheFailedEvent;
'components' => [
'cache' => [
'class' => CascadeCache::class,
'caches' => [
'redisCache',
[
'class' => \yii\caching\ArrayCache::class,
],
],
'cooldownDuration' => 60,
'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,
],
],
],