protected function _get_adv_data(&$value) { if (substr($value, 0, 18) == '__::foRMat_CacHe::' && preg_match('#^__::foRMat_CacHe::Type=(?P<type>[a-z0-9_]+),ExpKey=(?P<expkey>[a-f0-9]{32}),Exp=(?P<exp>[0-9,~/]+),SaveTime=(?P<savetime>[0-9]+),Value=(?P<value>.*)$#', $value, $match)) { #200~250,1/100 if (!preg_match('#^([0-9]+)~([0-9]+),([0-9]+)/([0-9]+)$#', $match['exp'], $match_exp)) { return true; } switch ($match['type']) { case Cache::TYPE_ADV_HIT: case Cache::TYPE_MAX_HIT: # 获取命中统计数 $exp = $this->driver->get($match['expkey']); break; case Cache::TYPE_ADV_AGE: case Cache::TYPE_MAX_AGE: default: $exp = TIME - $match['savetime']; break; } if ($exp >= $match_exp[0] && $exp <= $match_exp[1]) { # 在指定范围内按比例更新 $rand = mt_rand(1, $match_exp[3]); if ($rand <= $match_exp[2]) { # 命中,则清除数据,让程序可主动更新 $value = null; return null; } } elseif ($exp > $match_exp[1]) { # 强制认为没有获取数据 $value = null; return null; } if ($match['type'] == Cache::TYPE_ADV_HIT || $match['type'] == Cache::TYPE_MAX_HIT) { # 计数器增加 $this->driver->increment($match['expkey'], 1, $match_exp[1]); } $value = @unserialize($match['value']); } return null; }
/** * 关闭所有memcache链接 */ public static function close_all_connect() { if (!Cache_Driver_Memcache::$_memcached_mode) { foreach (Cache_Driver_Memcache::$memcaches as $config_name => $memcache) { try { $memcache->close(); } catch (Exception $e) { Core::debug()->error('close memcache connect error:' . $e); } Cache_Driver_Memcache::$memcaches[$config_name] = null; } } # 重置全部数据 Cache_Driver_Memcache::$memcaches = array(); Cache_Driver_Memcache::$memcaches_num = array(); if (IS_DEBUG) { Core::debug()->info('close all memcache server.'); } }