每天laravel-20160620|MemcachedConnector

namespace Illuminate\Cache;

use Memcached;
use Illuminate\Contracts\Cache\Store;
// a namespace about the user
class MemcachedStore extends TaggableStore implements Store
{// a Store about Memcache Store
/**
* The Memcached instance.
* The Memcached instance.
* @var \Memcached
*/
protected $memcached;

/**
 * A string that should be prepended to keys.
 * A string that should be prepended to keys.
 * @var string
 */
protected $prefix;// a string about the prefix.  with connection about the

/**
 * Create a new Memcached store.
 * Create a new Memcached store.
 * @param  \Memcached  $memcached
 * @param  string      $prefix
 * @return void
 */
public function __construct($memcached, $prefix = '')
{
    $this->setPrefix($prefix);
    $this->memcached = $memcached;
}// a supper big prefix

/**
 * Retrieve an item from the cache by key.
 * Retrieve an item form the cache by key.
 * @param  string|array  $key
 * @return mixed
 */
public function get($key)
{
    $value = $this->memcached->get($this->prefix.$key);// a way to get value

    if ($this->memcached->getResultCode() == 0) {
        return $value;
    }// if return value,
}// get a method

/**
 * Retrieve multiple items from the cache by key.
 * Retrieve multiple items from the cache by key.
 *
 * Items not found in the cache will have a null value.
 * Items not found in the cache will have a null value.
 * @param  array  $keys
 * @return array
 */
public function many(array $keys)
{
    $prefixedKeys = array_map(function ($key) {
        return $this->prefix.$key;
    }, $keys);// you are master ,

    $values = $this->memcached->getMulti($prefixedKeys, null, Memcached::GET_PRESERVE_ORDER);
  // more get
    if ($this->memcached->getResultCode() != 0) {
        return array_fill_keys($keys, null);
    }// get the result 

    return array_combine($keys, $values);
}// get a lot of keys

你可能感兴趣的:(namespace,memcached,缓存,Class,编辑器)