setValues() protected method

The default implementation calls Cache::setValue multiple times store values one by one. If the underlying cache storage supports multi-set, this method should be overridden to exploit that feature.
protected setValues ( array $data, integer $duration ) : array
$data array array where key corresponds to cache key while value is the value stored
$duration integer the number of seconds in which the cached values will expire. 0 means never expire.
return array array of failed keys
Beispiel #1
0
 /**
  * Stores multiple key-value pairs in cache.
  * @param array $data array where key corresponds to cache key while value is the value stored
  * @param integer $duration the number of seconds in which the cached values will expire. 0 means never expire.
  * @return array array of failed keys. Always empty in case of using memcached.
  */
 protected function setValues($data, $duration)
 {
     if ($this->useMemcached) {
         $this->_cache->setMulti($data, $duration > 0 ? $duration + time() : 0);
         return [];
     } else {
         return parent::setValues($data, $duration);
     }
 }
 /**
  * Stores multiple key-value pairs in cache.
  * @param array $data array where key corresponds to cache key while value is the value stored
  * @param integer $duration the number of seconds in which the cached values will expire. 0 means never expire.
  * @return array array of failed keys. Always empty in case of using memcached.
  */
 protected function setValues($data, $duration)
 {
     return parent::setValues($data, $duration);
 }
Beispiel #3
0
 /**
  * Stores multiple key-value pairs in cache.
  * @param array $data array where key corresponds to cache key while value is the value stored
  * @param int $duration the number of seconds in which the cached values will expire. 0 means never expire.
  * @return array array of failed keys. Always empty in case of using memcached.
  */
 protected function setValues($data, $duration)
 {
     if ($this->useMemcached) {
         // Use UNIX timestamp since it doesn't have any limitation
         // @see http://php.net/manual/en/memcache.set.php
         // @see http://php.net/manual/en/memcached.expiration.php
         $expire = $duration > 0 ? $duration + time() : 0;
         $this->_cache->setMulti($data, $expire);
         return [];
     } else {
         return parent::setValues($data, $duration);
     }
 }
 /**
  * Stores multiple key-value pairs in cache.
  * @param array $data array where key corresponds to cache key while value is the value stored
  * @param integer $expire the number of seconds in which the cached values will expire. 0 means never expire.
  * @return array array of failed keys. Always empty in case of using memcached.
  */
 protected function setValues($data, $expire)
 {
     if ($this->useMemcached) {
         if ($expire > 0) {
             $expire += time();
         } else {
             $expire = 0;
         }
         $this->_cache->setMulti($data, $expire);
         return [];
     } else {
         return parent::setValues($data, $expire);
     }
 }