当前位置: 首页>>代码示例>>PHP>>正文


PHP false::set_many方法代码示例

本文整理汇总了PHP中false::set_many方法的典型用法代码示例。如果您正苦于以下问题:PHP false::set_many方法的具体用法?PHP false::set_many怎么用?PHP false::set_many使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在false的用法示例。


在下文中一共展示了false::set_many方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: set_many

 /**
  * Sends several key => value pairs to the cache.
  *
  * Using this function comes with potential performance implications.
  * Not all cache stores will support get_many/set_many operations and in order to replicate this functionality will call
  * the equivalent singular method for each item provided.
  * This should not deter you from using this function as there is a performance benefit in situations where the cache store
  * does support it, but you should be aware of this fact.
  *
  * <code>
  * // This code will add four entries to the cache, one for each url.
  * $cache->set_many(array(
  *     'main' => 'http://moodle.org',
  *     'docs' => 'http://docs.moodle.org',
  *     'tracker' => 'http://tracker.moodle.org',
  *     'qa' => ''http://qa.moodle.net'
  * ));
  * </code>
  *
  * @param array $keyvaluearray An array of key => value pairs to send to the cache.
  * @return int The number of items successfully set. It is up to the developer to check this matches the number of items.
  *      ... if they care that is.
  */
 public function set_many(array $keyvaluearray)
 {
     if ($this->loader !== false) {
         // We have a loader available set it there as well.
         // We have to let the loader do its own parsing of data as it may be unique.
         $this->loader->set_many($keyvaluearray);
     }
     $data = array();
     $simulatettl = $this->has_a_ttl() && !$this->store_supports_native_ttl();
     $usestaticaccelerationarray = $this->use_static_acceleration();
     foreach ($keyvaluearray as $key => $value) {
         if (is_object($value) && $value instanceof cacheable_object) {
             $value = new cache_cached_object($value);
         } else {
             if (!is_scalar($value)) {
                 // If data is an object it will be a reference.
                 // If data is an array if may contain references.
                 // We want to break references so that the cache cannot be modified outside of itself.
                 // Call the function to unreference it (in the best way possible).
                 $value = $this->unref($value);
             }
         }
         if ($simulatettl) {
             $value = new cache_ttl_wrapper($value, $this->definition->get_ttl());
         }
         $data[$key] = array('key' => $this->parse_key($key), 'value' => $value);
         if ($usestaticaccelerationarray) {
             $this->static_acceleration_set($data[$key]['key'], $value);
         }
     }
     if ($this->perfdebug) {
         cache_helper::record_cache_set($this->storetype, $this->definition->get_id());
     }
     return $this->store->set_many($data);
 }
开发者ID:eamador,项目名称:moodle-course-custom-fields,代码行数:58,代码来源:loaders.php


注:本文中的false::set_many方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。