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


PHP Memcached::prependByKey方法代码示例

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


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

示例1: prepend

 /**
  * Prepend data to an existing item.
  *
  * This method should throw an error if it is used with compressed data. This is an expected behavior.
  * Memcached casts the value to be prepended to the initial value to the type of the initial value. Be
  * careful as this leads to unexpected behavior at times. For instance, prepending (float) 45.23 to
  * (int) 23 will result in 45, because the value is first combined (45.2323) then cast to "integer"
  * (the original value), which will be (int) 45. Due to how memcached treats types, the behavior has been
  * mimicked in the internal cache to produce similar results and improve consistency. It is recommend
  * that prepends only occur with data of the same type.
  *
  * @link    http://www.php.net/manual/en/memcached.prepend.php
  *
  * @param   string    $key          The key under which to store the value.
  * @param   string    $value        Must be string as prepending mixed values is not well-defined.
  * @param   string    $group        The group value prepended to the $key.
  * @param   string    $server_key   The key identifying the server to store the value on.
  * @param   bool      $byKey        True to store in internal cache by key; false to not store by key
  * @return  bool                    Returns TRUE on success or FALSE on failure.
  */
 public function prepend($key, $value, $group = 'default', $server_key = '', $byKey = false)
 {
     if (!is_string($value) && !is_int($value) && !is_float($value)) {
         return false;
     }
     $derived_key = $this->buildKey($key, $group);
     // If group is a non-Memcached group, prepend to runtime cache value, not Memcached
     if (in_array($group, $this->no_mc_groups)) {
         if (!isset($this->cache[$derived_key])) {
             return false;
         }
         $combined = $this->combine_values($this->cache[$derived_key], $value, 'pre');
         $this->add_to_internal_cache($derived_key, $combined);
         return true;
     }
     // Append to Memcached value
     if (false !== $byKey) {
         $result = $this->mc->prependByKey($server_key, $derived_key, $value);
     } else {
         $result = $this->mc->prepend($derived_key, $value);
     }
     // Store in runtime cache if add was successful
     if (Memcached::RES_SUCCESS === $this->getResultCode()) {
         $combined = $this->combine_values($this->cache[$derived_key], $value, 'pre');
         $this->add_to_internal_cache($derived_key, $combined);
     }
     return $result;
 }
开发者ID:Ramoonus,项目名称:wp-spider-cache,代码行数:48,代码来源:class-object-cache.php

示例2: prependByKey

 /**
  * @inheritdoc
  */
 public function prependByKey($server_key, $key, $value, $expiration = null)
 {
     $key = $this->prefix . $key;
     return parent::prependByKey($server_key, $key, $value, $expiration);
 }
开发者ID:jonafrank,项目名称:memcached-manager,代码行数:8,代码来源:MemcachedHandler.php


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