@ -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);
}