/// <summary> /// 重新设置Client属性,暂时只重设servers /// </summary> /// <param name="filePath">配置文件路径</param> /// <param name="keyName">SoketPool节点Xpath</param> public void Reload(string filePath, string keyName) { if (string.IsNullOrWhiteSpace(filePath)) { throw new ArgumentNullException(filePath); } if (string.IsNullOrWhiteSpace(keyName)) { throw new ArgumentNullException(keyName); } //todo:以后再重构 MemcachedClientConfiguration mcc = new MemcachedClientConfiguration(); #region 读取配置文件服务器节点信息,用于生成MemcachedClientConfiguration XmlHelper xml = new XmlHelper(filePath); string fullServerPath = string.Format(@"configuration/{0}/servers", keyName); XmlNode serverNode = xml.GetNode(fullServerPath); for (int i = 0; i < serverNode.ChildNodes.Count - 1; i++) { //这里过滤注释项 if (serverNode.ChildNodes[i].NodeType == XmlNodeType.Element) { var xmlAttributeCollection = serverNode.ChildNodes[i].Attributes; if (xmlAttributeCollection == null) { continue; } string add = xmlAttributeCollection["address"].Value.Trim(); string port = xmlAttributeCollection["port"].Value.Trim(); mcc.AddServer(add, Convert.ToInt32(port)); } } #endregion mcc.NodeLocator = typeof(DefaultNodeLocator); mcc.KeyTransformer = memClient.ClientConfiguration.CreateKeyTransformer(); mcc.Transcoder = memClient.ClientConfiguration.CreateTranscoder(); mcc.SocketPool.MinPoolSize = memClient.ClientConfiguration.SocketPool.MinPoolSize; mcc.SocketPool.MaxPoolSize = memClient.ClientConfiguration.SocketPool.MaxPoolSize; mcc.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 10); mcc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 30); memClient.ReSetMemcachedClient(mcc); }