示例#1
0
 /**
  *
  * @param string $endpoint
  * @throws Exception
  * @return \Memcache\Connection
  */
 public static function instance($endpoint = 'default')
 {
     if (!isset(self::$instances[$endpoint])) {
         if (!self::$configs) {
             self::$configs = (array) new \Config\Memcache();
         }
         $configs = self::$configs;
         if (!isset(self::$configs[$endpoint])) {
             throw new Exception('Config of "' . $endpoint . '" does not exist!', 100);
         }
         self::sanitizeConfig($configs[$endpoint]);
         self::$instances[$endpoint] = self::connect($configs[$endpoint]);
     }
     return self::$instances[$endpoint];
 }
 /**
  * get
  *
  * get a value from the memcache.
  *
  * @author eloy
  * @access public
  *
  * @param   string   $key     Key to get value
  *
  * @return mixed
  */
 public function get($key)
 {
     $value = null;
     try {
         $value = parent::get($key, self::FLAGS);
     } catch (Exception $e) {
         $value = null;
         wfDebugLog("memcachepool", "Error when getting value from key {$key}", true);
     }
     if ($this->_debug) {
         wfDebug(__METHOD__ . ": {$key} value is " . (is_null($value) ? "null" : "not null") . "\n");
     }
     return $value;
 }
 public function findServer($key)
 {
     if ($this->logging) {
         $start = microtime(true);
         $name = 'findServer';
         $arguments = array($key);
     }
     list($_key) = array($key);
     $result = parent::findServer($_key);
     list($key) = array($_key);
     if ($this->logging) {
         $time = microtime(true) - $start;
         $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result');
     }
     return $result;
 }