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."); } } } }
public memcachedAdapter(ILogging logger, CacheConfig config = null) { _logger = logger; var factory = new memcachedCacheFactory(_logger, config); _serverFarm = factory.ConstructCacheFarm(); if (_serverFarm == null || _serverFarm.NodeList == null || _serverFarm.NodeList.Count == 0) { throw new ArgumentException("Must specify at least 1 server node to use for memcached"); } Initialise(factory); LogManager.AssignFactory(new LogFactoryAdapter(_logger)); }