public ServerPool(IMemcachedClientConfiguration configuration)
        {
            if (configuration == null)
                throw new ArgumentNullException("configuration", "Invalid or missing pool configuration. Check if the enyim.com/memcached section or your custom section presents in the app/web.config.");

            this.configuration = configuration;
            this.isAliveTimer = new Timer(callback_isAliveTimer, null, (int)this.configuration.SocketPool.DeadTimeout.TotalMilliseconds, (int)this.configuration.SocketPool.DeadTimeout.TotalMilliseconds);

            // create the key transformer instance
            Type t = this.configuration.KeyTransformer;
            this.keyTransformer = (t == null) ? new DefaultKeyTransformer() : (IMemcachedKeyTransformer)Enyim.Reflection.FastActivator.CreateInstance(t);

            // create the item transcoder instance
            t = this.configuration.Transcoder;
            this.transcoder = (t == null) ? new DefaultTranscoder() : (ITranscoder)Enyim.Reflection.FastActivator.CreateInstance(t);

            // initialize the server list

            foreach (IPEndPoint ip in configuration.Servers)
            {
                this.workingServers.Add(MemcachedNode.Factory.Get(ip, configuration));
            }

            // (re)creates the locator
            this.RebuildIndexes();
        }
 public BinaryPool(IMemcachedClientConfiguration configuration, ILogger logger)
     : base(configuration, new BinaryOperationFactory(logger), logger)
 {
     this.authenticationProvider = GetProvider(configuration);
     this.configuration          = configuration;
     _logger = logger;
 }
Exemple #3
0
        public ServerPool(IMemcachedClientConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration", "Invalid or missing pool configuration. Check if the enyim.com/memcached section or your custom section presents in the app/web.config.");
            }

            this.configuration = configuration;
            this.isAliveTimer  = new Timer(callback_isAliveTimer, null, (int)this.configuration.SocketPool.DeadTimeout.TotalMilliseconds, (int)this.configuration.SocketPool.DeadTimeout.TotalMilliseconds);

            // create the key transformer instance
            Type t = this.configuration.KeyTransformer;

            this.keyTransformer = (t == null) ? new DefaultKeyTransformer() : (IMemcachedKeyTransformer)Activator.CreateInstance(t);

            // create the item transcoder instance
            t = this.configuration.Transcoder;
            this.transcoder = (t == null) ? new DefaultTranscoder() : (ITranscoder)Activator.CreateInstance(t);


            // initialize the server list
            ISocketPoolConfiguration ispc = configuration.SocketPool;

            foreach (IPEndPoint ip in configuration.Servers)
            {
                this.workingServers.Add(new MemcachedNode(ip, ispc));
            }

            // (re)creates the locator
            this.RebuildIndexes();
        }
Exemple #4
0
        private MemcachedCacheProvider(IMemcachedClientConfiguration config, TimeSpan?expiry, JsonSerializerSettings serializerSettings = null)
        {
            _serializerSettings = serializerSettings;

            Client = new MemcachedClient(Guard.NotNull(config, nameof(config)));
            Expiry = expiry;
        }
 public DefaultServerPool(IMemcachedClientConfiguration configuration, IOperationFactory opFactory)
 {
     this._configuration   = configuration ?? throw new ArgumentNullException(nameof(configuration), "Configuration is invalid");
     this._factory         = opFactory ?? throw new ArgumentNullException(nameof(opFactory), "Operation factory is invalid");
     this._deadTimeoutMsec = (int)this._configuration.SocketPool.DeadTimeout.TotalMilliseconds;
     this._logger          = Logger.CreateLogger <DefaultServerPool>();
 }
Exemple #6
0
 public MemcachedCachingProvider(IMemcachedClientConfiguration configuration)
 {
     if (null == configuration)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     Client = new MemcachedClient(configuration);
 }
        private static void ValidateConfig(IMemcachedClientConfiguration config)
        {
            Assert.IsNotNull(config);

            Assert.IsInstanceOf(typeof(TestKeyTransformer), config.CreateKeyTransformer());
            Assert.IsInstanceOf(typeof(TestLocator), config.CreateNodeLocator());
            Assert.IsInstanceOf(typeof(TestTranscoder), config.CreateTranscoder());
        }
Exemple #8
0
 public BinaryPool(IMemcachedClientConfiguration configuration) : base(configuration, new BinaryOperationFactory())
 {
     this._configuration          = configuration;
     this._authenticationProvider = configuration.Authentication != null && !string.IsNullOrWhiteSpace(configuration.Authentication.Type)
                         ? FastActivator.Create(configuration.Authentication.Type) as ISaslAuthenticationProvider
                         : null;
     this._authenticationProvider?.Initialize(configuration.Authentication.Parameters);
 }
Exemple #9
0
        /// <summary>
        /// Creates a server pool for auto discovery
        /// </summary>
        /// <param name="configuration">The client configuration using the pool</param>
        /// <param name="opFactory">The factory used to create operations on demand</param>
        /// <param name="loggerFactory">The factory to provide ILogger instance to each class.</param>
        public AutoServerPool(IMemcachedClientConfiguration configuration, IOperationFactory opFactory, ILoggerFactory loggerFactory)
        {
            _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
            _factory       = opFactory ?? throw new ArgumentNullException(nameof(opFactory));

            _deadTimeoutMsec = (long)_configuration.SocketPool.DeadTimeout.TotalMilliseconds;
            _loggerFactory   = loggerFactory;
            _log             = loggerFactory.CreateLogger <AutoServerPool>();
        }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:MemcachedClient"/> using the specified configuration.
        /// </summary>
        /// <param name="configuration">The client configuration.</param>
        public MemcachedClient(IMemcachedClientConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            this.pool = new ServerPool(configuration);
        }
Exemple #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MemcachedCachingProvider"/> class with a custom configuration provided.
        /// </summary>
        /// <param name="configuration">Memcached configuration object</param>
        public MemcachedCachingProvider(IMemcachedClientConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            Client = new MemcachedClient(configuration);
        }
Exemple #12
0
 public AutoBinaryPool(IMemcachedClientConfiguration configuration, ILoggerFactory loggerFactory)
     : base(configuration,
            new BinaryOperationFactory(loggerFactory.CreateLogger <BinaryOperationFactory>()),
            loggerFactory)
 {
     _authenticationProvider = GetProvider(configuration);
     _configuration          = configuration;
     _loggerFactory          = loggerFactory;
 }
        public MemcachedCache(IMemcachedClientConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            client = new MemcachedClient(configuration);
        }
		public DefaultServerPool(IMemcachedClientConfiguration configuration, IOperationFactory opFactory)
		{
			if (configuration == null) throw new ArgumentNullException("socketConfig");
			if (opFactory == null) throw new ArgumentNullException("opFactory");

			this.configuration = configuration;
			this.factory = opFactory;

			this.deadTimeoutMsec = (long)this.configuration.SocketPool.DeadTimeout.TotalMilliseconds;
		}
 static MemCacheProvider()
 {
     log    = LoggerProvider.LoggerFor(typeof(MemCacheProvider));
     config = ConfigurationManager.GetSection("enyim.com/memcached") as IMemcachedClientConfiguration;
     if (config == null)
     {
         log.Info("enyim.com/memcached configuration section not found, using default configuration (127.0.0.1:11211).");
         config = new MemcachedClientConfiguration();
         config.Servers.Add(new IPEndPoint(IPAddress.Loopback, 11211));
     }
 }
 static MemCacheProvider()
 {
     log = LoggerProvider.LoggerFor(typeof (MemCacheProvider));
     config = ConfigurationManager.GetSection("enyim.com/memcached") as IMemcachedClientConfiguration;
     if (config == null)
     {
         log.Info("enyim.com/memcached configuration section not found, using default configuration (127.0.0.1:11211).");
         config = new MemcachedClientConfiguration();
         config.Servers.Add(new IPEndPoint(IPAddress.Loopback, 11211));
     }
 }
    public WindowsAzureServerPool(string memcachedRoleName, string memcachedEndpointName, IMemcachedClientConfiguration configuration, IOperationFactory opFactory)
    {
        this.memcachedRoleName = memcachedRoleName;
        this.memcachedEndpointName = memcachedEndpointName;
        configuration = configuration ?? new MemcachedClientConfiguration();
        if (opFactory == null) throw new ArgumentNullException("opFactory");

        nodes = new Dictionary<string, IMemcachedNode>();

        this.configuration = configuration;
        this.factory = opFactory;
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:MemcachedClient"/> using the specified configuration instance.
        /// </summary>
        /// <param name="configuration">The memcachedClient configuration.</param>
        public static MemcachedClient CreateClient(IMemcachedClientConfiguration configuration)
        {
            if (configuration == null)
                throw new ArgumentNullException("configuration");

            sockIOPool = configuration.CreatePool();
            servers = configuration.Servers.Select(ip => ip.Address.ToString() + ":" + ip.Port).ToArray();

            memcachedClient = new MemcachedClient();
            memcachedClient.PoolName = sockIOPool.Name;
            memcachedClient.EnableCompression = false;

            return memcachedClient;
        }
Exemple #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:MemcachedClient"/> using the specified configuration instance.
        /// </summary>
        /// <param name="configuration">The memcachedClient configuration.</param>
        public MemcachedClient(IMemcachedClientConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            this.keyTransformer     = configuration.CreateKeyTransformer() ?? new DefaultKeyTransformer();
            this.transcoder         = configuration.CreateTranscoder() ?? new DefaultTranscoder();
            this.performanceMonitor = configuration.CreatePerformanceMonitor();

            this.pool = configuration.CreatePool();
            this.pool.Start();
        }
Exemple #20
0
        public WindowsAzureServerPool(string memcachedRoleName, string memcachedEndpointName, IMemcachedClientConfiguration configuration, IOperationFactory opFactory)
        {
            this.memcachedRoleName     = memcachedRoleName;
            this.memcachedEndpointName = memcachedEndpointName;
            configuration = configuration ?? new MemcachedClientConfiguration();
            if (opFactory == null)
            {
                throw new ArgumentNullException("opFactory");
            }

            nodes = new Dictionary <string, IMemcachedNode>();

            this.configuration = configuration;
            this.factory       = opFactory;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:MemcachedClient"/> using the specified configuration instance.
        /// </summary>
        /// <param name="configuration">The memcachedClient configuration.</param>
        public static MemcachedClient CreateClient(IMemcachedClientConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            sockIOPool = configuration.CreatePool();
            servers    = configuration.Servers.Select(ip => ip.Address.ToString() + ":" + ip.Port).ToArray();

            memcachedClient                   = new MemcachedClient();
            memcachedClient.PoolName          = sockIOPool.Name;
            memcachedClient.EnableCompression = false;

            return(memcachedClient);
        }
        public DefaultServerPool(IMemcachedClientConfiguration configuration, IOperationFactory opFactory)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("socketConfig");
            }
            if (opFactory == null)
            {
                throw new ArgumentNullException("opFactory");
            }

            this.configuration = configuration;
            this.factory       = opFactory;

            this.deadTimeoutMsec = (long)this.configuration.SocketPool.DeadTimeout.TotalMilliseconds;
        }
Exemple #23
0
		/// <summary>
		/// Initializes a new instance of the <see cref="T:MemcachedClient"/> using the specified configuration instance.
		/// </summary>
		/// <param name="configuration">The client configuration.</param>
		public MemcachedClient(IMemcachedClientConfiguration configuration)
		{
			if (configuration == null)
				throw new ArgumentNullException("configuration");

			this.keyTransformer = configuration.CreateKeyTransformer() ?? new DefaultKeyTransformer();
			this.transcoder = configuration.CreateTranscoder() ?? new DefaultTranscoder();
			this.performanceMonitor = configuration.CreatePerformanceMonitor();

			this.pool = configuration.CreatePool();
			this.pool.NodeFailed += (n) => { var f = this.NodeFailed; if (f != null) f(n); };
			this.StartPool();

			StoreOperationResultFactory = new DefaultStoreOperationResultFactory();
			GetOperationResultFactory = new DefaultGetOperationResultFactory();
			MutateOperationResultFactory = new DefaultMutateOperationResultFactory();
			ConcatOperationResultFactory = new DefaultConcatOperationResultFactory();
			RemoveOperationResultFactory = new DefaultRemoveOperationResultFactory();
		}
Exemple #24
0
		private static ISaslAuthenticationProvider GetProvider(IMemcachedClientConfiguration configuration)
		{
			// create&initialize the authenticator, if any
			// we'll use this single instance everywhere, so it must be thread safe
			IAuthenticationConfiguration auth = configuration.Authentication;
			if (auth != null)
			{
				Type t = auth.Type;
				var provider = (t == null) ? null : Enyim.Reflection.FastActivator.Create(t) as ISaslAuthenticationProvider;

				if (provider != null)
				{
					provider.Initialize(auth.Parameters);
					return provider;
				}
			}

			return null;
		}
Exemple #25
0
        private static ISaslAuthenticationProvider GetProvider(IMemcachedClientConfiguration configuration)
        {
            // create&initialize the authenticator, if any
            // we'll use this single instance everywhere, so it must be thread safe
            IAuthenticationConfiguration auth = configuration.Authentication;

            if (auth != null)
            {
                Type t        = auth.Type;
                var  provider = (t == null) ? null : IkCaching.Reflection.FastActivator.Create(t) as ISaslAuthenticationProvider;

                if (provider != null)
                {
                    provider.Initialize(auth.Parameters);
                    return(provider);
                }
            }

            return(null);
        }
 public MemcachedClientWrapper(IMemcachedClientConfiguration config)
     : base(new MemcachedClient(config))
 {
 }
Exemple #27
0
		public CustomBinaryPool(IMemcachedClientConfiguration configuration)
			: base(configuration, new BinaryOperationFactory())
		{
			this.authenticationProvider = GetProvider(configuration);
			this.configuration = configuration;
		}
Exemple #28
0
 public MemcachedClient(ILoggerFactory loggerFactory, IMemcachedClientConfiguration configuration)
 {
     _memcachedClient = new MemcachedClient(loggerFactory, configuration);
 }
Exemple #29
0
 public MemcachedEntityTagStore(IMemcachedClientConfiguration configuration)
 {
     _memcachedClient = new MemcachedClient(configuration);
 }
 public EasyCachingMemcachedClient(string name, ILoggerFactory loggerFactor, IMemcachedClientConfiguration configuration)
     : base(loggerFactor, configuration)
 {
     this._name = name;
 }
Exemple #31
0
 public BinaryPool(IMemcachedClientConfiguration configuration)
     : base(configuration, new BinaryOperationFactory())
 {
     this.authenticationProvider = GetProvider(configuration);
     this.configuration          = configuration;
 }
Exemple #32
0
 public ClientManager(IMemcachedClientConfiguration configuration)
 {
     this._client = new MemcachedClient(configuration);
 }
 public MemcachedStore(IMemcachedClientConfiguration configuration)
 {
     _memcachedClient = new MemcachedClient(configuration);
 }
 public MemcachedEntityTagStore12(IMemcachedClientConfiguration configuration)
 {
     _memcachedClient = new MemcachedClient(configuration);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MemcachedServiceCache"/> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 public MemcachedServiceCache(IMemcachedClientConfiguration configuration)
     : this(configuration == null ? new MemcachedClient() : new MemcachedClient(configuration), new TagMapper())
 {
 }
 public void TestVBucketConfig()
 {
     IMemcachedClientConfiguration config = ConfigurationManager.GetSection("test/vbucket") as IMemcachedClientConfiguration;
     var loc = config.CreateNodeLocator();
 }
        private void LoadClient(IMemcachedClientConfiguration config)
        {
            Enyim.Caching.LogManager.AssignFactory(new EnyimLogFactoryWrapper());

            _client = new MemcachedClient(config);
        }
Exemple #38
0
 public MemcachedClientCache(IMemcachedClientConfiguration memcachedClientConfiguration)
 {
     LoadClient(memcachedClientConfiguration);
 }
Exemple #39
0
 private void LoadClient(IMemcachedClientConfiguration config)
 {
     LogManager.LogFactory = new EnyimLogFactory();
     _client = new MemcachedClient(config);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MemcachedCachingProvider"/> class with the default settings based on the configuration file default section.
 /// </summary>
 public MemcachedCachingProvider(IMemcachedClientConfiguration configuration)
 {
     Client = new MemcachedClient(configuration);
 }
		public CustomMemcachedClient(IMemcachedClientConfiguration configuration)
			: base(configuration)
		{
		}
Exemple #42
0
 public CacheManager(ILoggerFactory loggerFactory, IMemcachedClientConfiguration configuration)
 {
     cacheClient = new MemcachedClient(loggerFactory, configuration);;
 }