diff --git a/Enyim.Caching/Configuration/MemcachedClientConfiguration.cs b/Enyim.Caching/Configuration/MemcachedClientConfiguration.cs index c2e69e76..000d6ca7 100755 --- a/Enyim.Caching/Configuration/MemcachedClientConfiguration.cs +++ b/Enyim.Caching/Configuration/MemcachedClientConfiguration.cs @@ -48,7 +48,24 @@ public MemcachedClientConfiguration( Servers.Add(new DnsEndPoint(server.Address, server.Port)); } } - SocketPool = options.SocketPool; + + SocketPool = new SocketPoolConfiguration(); + if (options.SocketPool != null) + { + SocketPool.MinPoolSize = options.SocketPool.MinPoolSize; + _logger.LogInformation($"{nameof(SocketPool.MinPoolSize)}: {SocketPool.MinPoolSize}"); + SocketPool.MaxPoolSize = options.SocketPool.MaxPoolSize; + _logger.LogInformation($"{nameof(SocketPool.MaxPoolSize)}: {SocketPool.MaxPoolSize}"); + SocketPool.ConnectionTimeout = options.SocketPool.ConnectionTimeout; + _logger.LogInformation($"{nameof(SocketPool.ConnectionTimeout)}: {SocketPool.ConnectionTimeout}"); + SocketPool.ReceiveTimeout = options.SocketPool.ReceiveTimeout; + _logger.LogInformation($"{nameof(SocketPool.ReceiveTimeout)}: {SocketPool.ReceiveTimeout}"); + SocketPool.DeadTimeout = options.SocketPool.DeadTimeout; + _logger.LogInformation($"{nameof(SocketPool.DeadTimeout)}: {SocketPool.DeadTimeout}"); + SocketPool.QueueTimeout = options.SocketPool.QueueTimeout; + _logger.LogInformation($"{nameof(SocketPool.QueueTimeout)}: {SocketPool.QueueTimeout}"); + } + Protocol = options.Protocol; if (options.Authentication != null && !string.IsNullOrEmpty(options.Authentication.Type)) diff --git a/Enyim.Caching/Configuration/MemcachedClientOptions.cs b/Enyim.Caching/Configuration/MemcachedClientOptions.cs index 43727354..325db5c6 100644 --- a/Enyim.Caching/Configuration/MemcachedClientOptions.cs +++ b/Enyim.Caching/Configuration/MemcachedClientOptions.cs @@ -11,7 +11,7 @@ public class MemcachedClientOptions : IOptions { public MemcachedProtocol Protocol { get; set; } = MemcachedProtocol.Binary; - public SocketPoolConfiguration SocketPool { get; set; } = new SocketPoolConfiguration(); + public SocketPoolOptions SocketPool { get; set; } public List Servers { get; set; } = new List(); @@ -57,4 +57,14 @@ public class Authentication public Dictionary Parameters { get; set; } } + + public class SocketPoolOptions + { + public int MinPoolSize { get; set; } = 10; + public int MaxPoolSize { get; set; } = 20; + public TimeSpan ConnectionTimeout { get; set; } = new TimeSpan(0, 0, 10); + public TimeSpan ReceiveTimeout { get; set; } = new TimeSpan(0, 0, 10); + public TimeSpan DeadTimeout { get; set; } = new TimeSpan(0, 0, 10); + public TimeSpan QueueTimeout { get; set; } = new TimeSpan(0, 0, 0, 0, 100); + } } diff --git a/Enyim.Caching/Enyim.Caching.csproj b/Enyim.Caching/Enyim.Caching.csproj index e0c0e972..994b11d7 100755 --- a/Enyim.Caching/Enyim.Caching.csproj +++ b/Enyim.Caching/Enyim.Caching.csproj @@ -2,7 +2,7 @@ EnyimMemcachedCore is a Memcached client library for .NET Core. Usage: Add services.AddEnyimMemcached(...) and app.UseEnyimMemcached() in Startup. Add IMemcachedClient into constructor. - 2.0.3 + 2.0.4 cnblogs.com netstandard2.0 true diff --git a/SampleWebApp/Startup.cs b/SampleWebApp/Startup.cs index d8a8db8e..ff20ff39 100644 --- a/SampleWebApp/Startup.cs +++ b/SampleWebApp/Startup.cs @@ -31,19 +31,8 @@ public Startup(IHostingEnvironment env) public void ConfigureServices(IServiceCollection services) { - if (IsDevelopment) - { - services.AddEnyimMemcached(options => - { - options.AddServer("memcached", 11211); - //options.AddPlainTextAuthenticator("", "usename", "password"); - }); - } - else - { - services.AddEnyimMemcached(Configuration.GetSection("enyimMemcached")); - } - } + services.AddEnyimMemcached(Configuration.GetSection("enyimMemcached")); + } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { diff --git a/SampleWebApp/appsettings.json b/SampleWebApp/appsettings.json index aec0f360..cb1e56bc 100644 --- a/SampleWebApp/appsettings.json +++ b/SampleWebApp/appsettings.json @@ -5,7 +5,16 @@ "Address": "memcached", "Port": 11211 } - ]//, + ], + "socketPool": { + "minPoolSize": "5", + "maxPoolSize": "25", + "connectionTimeout": "15", + "receiveTimeout": "15", + "deadTimeout": "15", + "queueTimeout": "150" + } + //, //"KeyTransformer": "Enyim.Caching.Memcached.SHA1KeyTransformer" //, //"Authentication": {