コード例 #1
0
        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);
        }
コード例 #2
0
 public override void Dispose()
 {
     if (_memcachedClient != null)
     {
         _memcachedClient.Dispose();
     }
 }
コード例 #3
0
 public void FixtureTearDown()
 {
     if (Client != null)
     {
         Client.Dispose();
     }
 }
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         _memcachedClient.Dispose();
     }
 }
コード例 #5
0
 public void Stop()
 {
     lock (syncObject)
     {
         clientInstance.Dispose();
         clientInstance = null;
     }
 }
コード例 #6
0
 private void ButtonExit_Click(object sender, EventArgs e)
 {
     if (_mem != null)
     {
         _mem.Dispose();
     }
     Application.Exit();
 }
コード例 #7
0
 public void Dispose()
 {
     if (client != null)
     {
         client.Dispose();
     }
     GC.Collect();
 }
コード例 #8
0
        public void Dispose()
        {
            if (memClient == null)
            {
                return;
            }

            memClient.Dispose();
            memClient = null;
        }
コード例 #9
0
        public async Task CloseAsync(string correlationId)
        {
            if (_client != null)
            {
                _client.Dispose();
                _client = null;
            }

            await Task.Delay(0);
        }
コード例 #10
0
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             _cached?.Dispose();
         }
     }
     _disposed = true;
 }
コード例 #11
0
 /// <inheritdoc />
 public void Stop()
 {
     lock (syncObject)
     {
         _usageCount--;
         if (_usageCount <= 0)
         {
             clientInstance?.Dispose();
             clientInstance = null;
             _usageCount    = 0;
         }
     }
 }
コード例 #12
0
        /// <summary>
        /// 关闭客户端连接
        /// </summary>
        /// <returns></returns>
        public bool Close()
        {
            var result = true;

            try
            {
                _cacheClient.Dispose();
            }
            catch
            {
                result = false;
            }
            return(result);
        }
コード例 #13
0
        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();
        }
コード例 #14
0
        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);
        }
コード例 #15
0
ファイル: Cache.cs プロジェクト: omufeed/CachingDemo
        private static void ResetMemcachedClient()
        {
            try
            {
                memcachedClient.Dispose();
            }
            catch (NullReferenceException)
            {
                //Do nothing
            }
            finally
            {
                Runtime.Remove("MemcachedClient");
                memcachedClient = null;

                ConnectMemcachedClient();
            }
        }
コード例 #16
0
        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();
        }
コード例 #17
0
ファイル: Memcached.cs プロジェクト: Jonkins/Pokefans
 /// <summary>
 /// Dispose the cache object
 /// </summary>
 public override void Dispose()
 {
     _memcachedClient.Dispose();
     _memcachedClient = null;
     Connected        = false;
 }
コード例 #18
0
 public void Dispose()
 {
     _client?.Dispose();
     _client = null;
 }
コード例 #19
0
 public void Dispose()
 {
     client.Dispose();
 }
コード例 #20
0
 public void Dispose()
 {
     _memcachedClient.Dispose();
 }
コード例 #21
0
        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;
        }
コード例 #22
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     _cacheObject.Dispose();
 }
コード例 #23
0
        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;
        }
コード例 #24
0
 /// <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;
 }