public MemcachedClient GetClient() { // caches the ignored urls to prevent a query to the settings var servers = _cacheManager.Get("MemcachedSettingsPart.Servers", context => { context.Monitor(_signals.When(MemcachedSettingsPart.CacheKey)); var part = _service.Value.GetSiteSettings().As <MemcachedSettingsPart>(); // initializes the client to notify it has to be constructed again lock (_synLock) { if (_client != null) { _client.Dispose(); } _client = null; } return(part.Servers); } ); if (_client == null && !String.IsNullOrEmpty(servers)) { var configuration = new MemcachedClientConfiguration(); using (var urlReader = new StringReader(servers)) { string server; // ignore empty lines and comments (#) while (null != (server = urlReader.ReadLine())) { if (String.IsNullOrWhiteSpace(server) || server.Trim().StartsWith("#")) { continue; } var values = server.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int port = 11211; if (values.Length == 2) { Int32.TryParse(values[1], out port); } if (values.Length > 0) { configuration.AddServer(values[0], port); } } lock (_synLock) { _client = new MemcachedClient(configuration); } } } return(_client); }
public override void Dispose() { if (_memcachedClient != null) { _memcachedClient.Dispose(); } }
public void FixtureTearDown() { if (Client != null) { Client.Dispose(); } }
private void Dispose(bool disposing) { if (disposing) { _memcachedClient.Dispose(); } }
public void Stop() { lock (syncObject) { clientInstance.Dispose(); clientInstance = null; } }
private void ButtonExit_Click(object sender, EventArgs e) { if (_mem != null) { _mem.Dispose(); } Application.Exit(); }
public void Dispose() { if (client != null) { client.Dispose(); } GC.Collect(); }
public void Dispose() { if (memClient == null) { return; } memClient.Dispose(); memClient = null; }
public async Task CloseAsync(string correlationId) { if (_client != null) { _client.Dispose(); _client = null; } await Task.Delay(0); }
protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { _cached?.Dispose(); } } _disposed = true; }
/// <inheritdoc /> public void Stop() { lock (syncObject) { _usageCount--; if (_usageCount <= 0) { clientInstance?.Dispose(); clientInstance = null; _usageCount = 0; } } }
/// <summary> /// 关闭客户端连接 /// </summary> /// <returns></returns> public bool Close() { var result = true; try { _cacheClient.Dispose(); } catch { result = false; } return(result); }
public void InitialRequestTest() { // The url below is used to bypass the .cfg. contraint of the hostname for testing locally ClusterConfigSettings settings = new ClusterConfigSettings("www.cfg.org", 11211); settings.NodeFactory = new NodeFactory(); config = new ElastiCacheClusterConfig(loggerFactory, settings); client = new MemcachedClient(loggerFactory, config); Assert.AreEqual(new Version("1.4.14"), config.DiscoveryNode.NodeVersion); Assert.AreEqual(1, config.DiscoveryNode.ClusterVersion); Assert.AreEqual(3, config.DiscoveryNode.NodesInCluster); this.config.DiscoveryNode.Dispose(); client.Dispose(); }
public override Server creack(String ip, int port, String username, String password, int timeOut) { MemcachedClient conn = null; Server server = new Server(); try { MemcachedClientConfiguration memConfig = new MemcachedClientConfiguration(); IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(ip), port); //配置文件 - ip memConfig.Servers.Add(ipEndPoint); //配置文件 - 协议 memConfig.Protocol = MemcachedProtocol.Binary; //配置文件-权限,如果使用了免密码功能,则无需设置userName和password memConfig.Authentication.Type = typeof(PlainTextAuthenticator); memConfig.Authentication.Parameters["zone"] = ""; if (!"空".Equals(password)) { memConfig.Authentication.Parameters["userName"] = username; memConfig.Authentication.Parameters["password"] = password; } //下面请根据实例的最大连接数进行设置 memConfig.SocketPool.MinPoolSize = 1; memConfig.SocketPool.MaxPoolSize = 1; memConfig.SocketPool.ConnectionTimeout = TimeSpan.FromSeconds(timeOut); memConfig.SocketPool.ReceiveTimeout = TimeSpan.FromSeconds(timeOut); memConfig.SocketPool.DeadTimeout = TimeSpan.FromSeconds(timeOut); conn = new MemcachedClient(memConfig); server.isSuccess = true; } catch (Exception e) { throw e; } finally { if (conn != null) { conn.Dispose(); } } return(server); }
private static void ResetMemcachedClient() { try { memcachedClient.Dispose(); } catch (NullReferenceException) { //Do nothing } finally { Runtime.Remove("MemcachedClient"); memcachedClient = null; ConnectMemcachedClient(); } }
public void PollerTesting() { //Poller is set to poll every second to make this test faster ClusterConfigSettings settings = new ClusterConfigSettings("www.cfg.org", 11211); settings.NodeFactory = new NodeFactory(); settings.ClusterPoller.IntervalDelay = 1000; config = new ElastiCacheClusterConfig(settings); client = new MemcachedClient(config); // Buffer time to wait, this can fail occasionally because delays can occur in the poller or timer System.Threading.Thread.Sleep(3000); Assert.AreEqual(3, config.DiscoveryNode.ClusterVersion); Assert.AreEqual(1, config.DiscoveryNode.NodesInCluster); this.config.DiscoveryNode.Dispose(); client.Dispose(); }
/// <summary> /// Dispose the cache object /// </summary> public override void Dispose() { _memcachedClient.Dispose(); _memcachedClient = null; Connected = false; }
public void Dispose() { _client?.Dispose(); _client = null; }
public void Dispose() { client.Dispose(); }
public void Dispose() { _memcachedClient.Dispose(); }
private static long TestMemcachedRead(int length) { var client = new MemcachedClient(); var sw = Stopwatch.StartNew(); for (int i = 0; i < length; i++) { var result = client.ExecuteGet("asdfasdf" + i.ToString()).Value.ToString(); if (result != stringToTest) throw new Exception(); } sw.Stop(); client.Dispose(); return sw.ElapsedMilliseconds; }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { _cacheObject.Dispose(); }
private static long TestMemcachedWrite(int length) { var client = new MemcachedClient(); var sw = Stopwatch.StartNew(); for (int i = 0; i < length; i++) { client.Store(StoreMode.Set, "asdfasdf" + i.ToString(), stringToTest); } sw.Stop(); client.Dispose(); return sw.ElapsedMilliseconds; }
/// <summary> /// Release memory for the default and search cache. Var will be null after this call. /// (You can caal init again!) /// </summary> public static void Done() { defaultCache.Dispose(); defaultCache = null; }