From 5a47692e64938a937b653040527360f6cadd116c Mon Sep 17 00:00:00 2001 From: githubjeka Date: Tue, 1 Dec 2015 14:29:43 +0300 Subject: [PATCH 1/4] Create multiSet, multiGet, multiAdd methods, and mark mset, mget and madd as deprecated --- framework/caching/Cache.php | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/framework/caching/Cache.php b/framework/caching/Cache.php index 68e11e8..0b96281 100644 --- a/framework/caching/Cache.php +++ b/framework/caching/Cache.php @@ -141,6 +141,8 @@ abstract class Cache extends Component implements \ArrayAccess * Some caches (such as memcache, apc) allow retrieving multiple cached values at the same time, * which may improve the performance. In case a cache does not support this feature natively, * this method will try to simulate it. + * + * @deprecated This method is alias as [[multiGet()]] and will be removed in 2.1.0. * @param string[] $keys list of string keys identifying the cached values * @return array list of cached values corresponding to the specified keys. The array * is returned in terms of (key, value) pairs. @@ -148,6 +150,21 @@ abstract class Cache extends Component implements \ArrayAccess */ public function mget($keys) { + return $this->multiGet($keys); + } + + /** + * Retrieves multiple values from cache with the specified keys. + * Some caches (such as memcache, apc) allow retrieving multiple cached values at the same time, + * which may improve the performance. In case a cache does not support this feature natively, + * this method will try to simulate it. + * @param string[] $keys list of string keys identifying the cached values + * @return array list of cached values corresponding to the specified keys. The array + * is returned in terms of (key, value) pairs. + * If a value is not cached or expired, the corresponding array value will be false. + */ + public function multiGet($keys) + { $keyMap = []; foreach ($keys as $key) { $keyMap[$key] = $this->buildKey($key); @@ -207,6 +224,7 @@ abstract class Cache extends Component implements \ArrayAccess * If the cache already contains such a key, the existing value and * expiration time will be replaced with the new ones, respectively. * + * @deprecated This method is alias as [[multiSet()]] and will be removed in 2.1.0. * * @param array $items the items to be cached, as key-value pairs. * @param integer $duration default number of seconds in which the cached values will expire. 0 means never expire. * @param Dependency $dependency dependency of the cached items. If the dependency changes, @@ -216,6 +234,23 @@ abstract class Cache extends Component implements \ArrayAccess */ public function mset($items, $duration = 0, $dependency = null) { + return $this->multiSet($items, $duration, $dependency); + } + + /** + * Stores multiple items in cache. Each item contains a value identified by a key. + * If the cache already contains such a key, the existing value and + * expiration time will be replaced with the new ones, respectively. + * + * @param array $items the items to be cached, as key-value pairs. + * @param integer $duration default number of seconds in which the cached values will expire. 0 means never expire. + * @param Dependency $dependency dependency of the cached items. If the dependency changes, + * the corresponding values in the cache will be invalidated when it is fetched via [[get()]]. + * This parameter is ignored if [[serializer]] is false. + * @return boolean whether the items are successfully stored into cache + */ + public function multiSet($items, $duration = 0, $dependency = null) + { if ($dependency !== null && $this->serializer !== false) { $dependency->evaluateDependency($this); } @@ -239,6 +274,7 @@ abstract class Cache extends Component implements \ArrayAccess * Stores multiple items in cache. Each item contains a value identified by a key. * If the cache already contains such a key, the existing value and expiration time will be preserved. * + * @deprecated This method is alias as [[multiAdd()]] and will be removed in 2.1.0. * @param array $items the items to be cached, as key-value pairs. * @param integer $duration default number of seconds in which the cached values will expire. 0 means never expire. * @param Dependency $dependency dependency of the cached items. If the dependency changes, @@ -248,6 +284,22 @@ abstract class Cache extends Component implements \ArrayAccess */ public function madd($items, $duration = 0, $dependency = null) { + return $this->multiAdd($items, $duration, $dependency); + } + + /** + * Stores multiple items in cache. Each item contains a value identified by a key. + * If the cache already contains such a key, the existing value and expiration time will be preserved. + * + * @param array $items the items to be cached, as key-value pairs. + * @param integer $duration default number of seconds in which the cached values will expire. 0 means never expire. + * @param Dependency $dependency dependency of the cached items. If the dependency changes, + * the corresponding values in the cache will be invalidated when it is fetched via [[get()]]. + * This parameter is ignored if [[serializer]] is false. + * @return boolean whether the items are successfully stored into cache + */ + public function multiAdd($items, $duration = 0, $dependency = null) + { if ($dependency !== null && $this->serializer !== false) { $dependency->evaluateDependency($this); } From c750bb1577376e795c494243ac122a1884901b9b Mon Sep 17 00:00:00 2001 From: githubjeka Date: Tue, 1 Dec 2015 14:36:01 +0300 Subject: [PATCH 2/4] update changelog --- framework/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 7220934..be5678e 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -79,6 +79,7 @@ Yii Framework 2 Change Log - Chg #9953: `TimestampBehavior::getValue()` changed to make value processing consistent with `AttributeBehavior::getValue()` (silverfire) - Chg #6419: Added `yii\web\ErrorHandler::displayVars` make list of displayed vars customizable. `$_ENV` and `$_SERVER` are not displayed by default anymore (silverfire) - Chg #9528: Traversable objects are now formatted as arrays in `yii\web\XmlResponseFormatter` to support SPL objects and Generators (MaXL-ru) +- Chg #10296: Methods mset, mget and madd have been marked as deprecated (trejder, githubjeka) - New #10083: Added wrapper for PHP webserver (samdark) - New: Added new requirement: ICU Data version >= 49.1 (SilverFire) From b52cbd11f8bdc27ac1342bba1dc4027ee102d05d Mon Sep 17 00:00:00 2001 From: githubjeka Date: Tue, 1 Dec 2015 14:37:15 +0300 Subject: [PATCH 3/4] update changelog --- framework/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index be5678e..8add9c6 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -79,7 +79,7 @@ Yii Framework 2 Change Log - Chg #9953: `TimestampBehavior::getValue()` changed to make value processing consistent with `AttributeBehavior::getValue()` (silverfire) - Chg #6419: Added `yii\web\ErrorHandler::displayVars` make list of displayed vars customizable. `$_ENV` and `$_SERVER` are not displayed by default anymore (silverfire) - Chg #9528: Traversable objects are now formatted as arrays in `yii\web\XmlResponseFormatter` to support SPL objects and Generators (MaXL-ru) -- Chg #10296: Methods mset, mget and madd have been marked as deprecated (trejder, githubjeka) +- Chg #10296: Methods mset, mget and madd of \yii\caching\Cache have been marked as deprecated (trejder, githubjeka) - New #10083: Added wrapper for PHP webserver (samdark) - New: Added new requirement: ICU Data version >= 49.1 (SilverFire) From 12c738c058e449bc61df5f900ce7c89449c0f119 Mon Sep 17 00:00:00 2001 From: githubjeka Date: Tue, 1 Dec 2015 20:56:20 +0300 Subject: [PATCH 4/4] Cosmetic --- framework/CHANGELOG.md | 2 +- framework/caching/Cache.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 8add9c6..34b533e 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -79,7 +79,7 @@ Yii Framework 2 Change Log - Chg #9953: `TimestampBehavior::getValue()` changed to make value processing consistent with `AttributeBehavior::getValue()` (silverfire) - Chg #6419: Added `yii\web\ErrorHandler::displayVars` make list of displayed vars customizable. `$_ENV` and `$_SERVER` are not displayed by default anymore (silverfire) - Chg #9528: Traversable objects are now formatted as arrays in `yii\web\XmlResponseFormatter` to support SPL objects and Generators (MaXL-ru) -- Chg #10296: Methods mset, mget and madd of \yii\caching\Cache have been marked as deprecated (trejder, githubjeka) +- Chg #10296: Methods mset, mget and madd of `\yii\caching\Cache` have been marked as deprecated (trejder, githubjeka) - New #10083: Added wrapper for PHP webserver (samdark) - New: Added new requirement: ICU Data version >= 49.1 (SilverFire) diff --git a/framework/caching/Cache.php b/framework/caching/Cache.php index 0b96281..013a174 100644 --- a/framework/caching/Cache.php +++ b/framework/caching/Cache.php @@ -224,7 +224,7 @@ abstract class Cache extends Component implements \ArrayAccess * If the cache already contains such a key, the existing value and * expiration time will be replaced with the new ones, respectively. * - * @deprecated This method is alias as [[multiSet()]] and will be removed in 2.1.0. * + * @deprecated This method is alias as [[multiSet()]] and will be removed in 2.1.0. * @param array $items the items to be cached, as key-value pairs. * @param integer $duration default number of seconds in which the cached values will expire. 0 means never expire. * @param Dependency $dependency dependency of the cached items. If the dependency changes,