mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-17 06:48:59 +08:00
Create multiSet, multiGet, multiAdd methods, and mark mset, mget and madd as deprecated
This commit is contained in:
@@ -141,12 +141,29 @@ 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.
|
||||
* If a value is not cached or expired, the corresponding array value will be false.
|
||||
*/
|
||||
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) {
|
||||
@@ -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,
|
||||
@@ -215,6 +233,23 @@ abstract class Cache extends Component implements \ArrayAccess
|
||||
* @return boolean whether the items are successfully stored into cache
|
||||
*/
|
||||
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,
|
||||
@@ -247,6 +283,22 @@ abstract class Cache extends Component implements \ArrayAccess
|
||||
* @return boolean whether the items are successfully stored into cache
|
||||
*/
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user