private ICache CreateCacheEngine() { if (!_isInitialised) { lock (_lockRef) { if (!_isInitialised) { _isInitialised = true; var config = new Enyim.Caching.Configuration.MemcachedClientConfiguration(); var serverFarm = ConstructCacheFarm(); serverFarm.NodeList.ForEach(n => config.AddServer(n.IPAddressOrHostName, n.Port)); config.SocketPool.ConnectionTimeout = ConnectTimeout; config.SocketPool.DeadTimeout = DeadNodeTimeout; config.SocketPool.MaxPoolSize = MaximumPoolSize; config.SocketPool.MinPoolSize = MinimumPoolSize; // Note: Tried using the Binary protocol here but I consistently got unreliable results in tests. // TODO: Need to investigate further why Binary protocol is unreliable in this scenario. // Could be related to memcached version and/or transcoder. config.Protocol = MemcachedProtocol.Text; config.Transcoder = new DataContractTranscoder(); _client = new MemcachedClient(config); Logger.WriteInfoMessage("memcachedAdapter initialised."); LogManager.AssignFactory(new LogFactoryAdapter(Logger)); } } } return(new memcachedAdapter(Logger, _client)); }
private void Initialise(memcachedCacheFactory factory) { if (!_isInitialised) { lock (_lockRef) { if (!_isInitialised) { _isInitialised = true; // If the consumer of this class has passed in a IMemcachedClient //instance, then we use that instead if (_client != null) { return; } var config = new Enyim.Caching.Configuration.MemcachedClientConfiguration(); _serverFarm.NodeList.ForEach(n => config.AddServer(n.IPAddressOrHostName, n.Port)); config.SocketPool.ConnectionTimeout = factory.ConnectTimeout; config.SocketPool.DeadTimeout = factory.DeadNodeTimeout; config.SocketPool.MaxPoolSize = factory.MaximumPoolSize; config.SocketPool.MinPoolSize = factory.MinimumPoolSize; config.Protocol = MemcachedProtocol.Text; config.Transcoder = new DataContractTranscoder(); _client = new MemcachedClient(config); _logger.WriteInfoMessage("memcachedAdapter initialised."); } } } }
private ICache CreateCacheEngine() { if (!_isInitialised) { lock (_lockRef) { if (!_isInitialised) { _isInitialised = true; var config = new Enyim.Caching.Configuration.MemcachedClientConfiguration(); var serverFarm = ConstructCacheFarm(); serverFarm.NodeList.ForEach(n => config.AddServer(n.IPAddressOrHostName, n.Port)); config.SocketPool.ConnectionTimeout = ConnectTimeout; config.SocketPool.DeadTimeout = DeadNodeTimeout; config.SocketPool.MaxPoolSize = MaximumPoolSize; config.SocketPool.MinPoolSize = MinimumPoolSize; // Note: Tried using the Binary protocol here but I consistently got unreliable results in tests. // TODO: Need to investigate further why Binary protocol is unreliable in this scenario. // Could be related to memcached version and/or transcoder. var protocol = MemcachedProtocol.Text; if (!string.IsNullOrWhiteSpace(Protocol)) { Enum.TryParse(Protocol, true, out protocol); } config.Protocol = protocol; config.Transcoder = new DataContractTranscoder(); if (!string.IsNullOrWhiteSpace(UserName) && !string.IsNullOrWhiteSpace(Password)) { config.Authentication.Type = typeof(PlainTextAuthenticator); config.Authentication.Parameters.Add("userName", UserName); config.Authentication.Parameters.Add("password", Password); config.Authentication.Parameters.Add("zone", string.Empty); } _client = new MemcachedClient(config); Logger.WriteInfoMessage("memcachedAdapter initialised."); LogManager.AssignFactory(new LogFactoryAdapter(Logger)); } } } return(new memcachedAdapter(Logger, _client)); }