From 5311dac9046f90c2ef9b7480d819eaa0c36b2322 Mon Sep 17 00:00:00 2001 From: Panagiotis Moustafellos Date: Sat, 24 Aug 2013 19:01:47 +0300 Subject: [PATCH] Added failureCallback, reduced timeouts to 1s --- framework/yii/caching/MemCache.php | 2 +- framework/yii/caching/MemCacheServer.php | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/framework/yii/caching/MemCache.php b/framework/yii/caching/MemCache.php index 86a0b45..7ebef70 100644 --- a/framework/yii/caching/MemCache.php +++ b/framework/yii/caching/MemCache.php @@ -94,7 +94,7 @@ class MemCache extends Cache $cache->addServer($server->host, $server->port, $server->weight); } else { $cache->addServer($server->host, $server->port, $server->persistent, - $server->weight, $server->timeout, $server->retryInterval, $server->status, null, $server->timemoutms); + $server->weight, $server->timeout, $server->retryInterval, $server->status, $server->failureCallback, $server->timemoutms); } } } else { diff --git a/framework/yii/caching/MemCacheServer.php b/framework/yii/caching/MemCacheServer.php index 5081963..be3d8dc 100644 --- a/framework/yii/caching/MemCacheServer.php +++ b/framework/yii/caching/MemCacheServer.php @@ -37,7 +37,7 @@ class MemCacheServer extends \yii\base\Object /** * @var integer value in seconds which will be used for connecting to the server. This is used by memcache only. */ - public $timeout = 2; + public $timeout = 1; /** * @var integer how often a failed server will be retried (in seconds). This is used by memcache only. */ @@ -47,8 +47,14 @@ class MemCacheServer extends \yii\base\Object */ public $status = true; /** - * @var integer value in milliseconds which will be used for connecting to the server. - * Takes precedence over timeout. This is used by memcache only. - */ - public $timemoutms = 2000; + * @var \Closure allows the user to specify a callback function to run upon encountering an error. + * The callback is run before failover is attempted. The function takes two parameters, + * the [[host]] and the [[port]] of the failed server. + */ + public $failureCallback = null; + /** + * @var integer value in milliseconds which will be used for connecting to the server. + * Takes precedence over [[timeout]]. This is used by memcache only. + */ + public $timemoutms = 1000; }