Skip to content

Commit d0a01df

Browse files
authored
Merge pull request #32 from cnblogs/hotfix-31
Fix unable to read socket pool configuration from appsettings(#31)
2 parents 89b98d8 + e42f8b0 commit d0a01df

File tree

5 files changed

+42
-17
lines changed

5 files changed

+42
-17
lines changed

Enyim.Caching/Configuration/MemcachedClientConfiguration.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,24 @@ public MemcachedClientConfiguration(
4848
Servers.Add(new DnsEndPoint(server.Address, server.Port));
4949
}
5050
}
51-
SocketPool = options.SocketPool;
51+
52+
SocketPool = new SocketPoolConfiguration();
53+
if (options.SocketPool != null)
54+
{
55+
SocketPool.MinPoolSize = options.SocketPool.MinPoolSize;
56+
_logger.LogInformation($"{nameof(SocketPool.MinPoolSize)}: {SocketPool.MinPoolSize}");
57+
SocketPool.MaxPoolSize = options.SocketPool.MaxPoolSize;
58+
_logger.LogInformation($"{nameof(SocketPool.MaxPoolSize)}: {SocketPool.MaxPoolSize}");
59+
SocketPool.ConnectionTimeout = options.SocketPool.ConnectionTimeout;
60+
_logger.LogInformation($"{nameof(SocketPool.ConnectionTimeout)}: {SocketPool.ConnectionTimeout}");
61+
SocketPool.ReceiveTimeout = options.SocketPool.ReceiveTimeout;
62+
_logger.LogInformation($"{nameof(SocketPool.ReceiveTimeout)}: {SocketPool.ReceiveTimeout}");
63+
SocketPool.DeadTimeout = options.SocketPool.DeadTimeout;
64+
_logger.LogInformation($"{nameof(SocketPool.DeadTimeout)}: {SocketPool.DeadTimeout}");
65+
SocketPool.QueueTimeout = options.SocketPool.QueueTimeout;
66+
_logger.LogInformation($"{nameof(SocketPool.QueueTimeout)}: {SocketPool.QueueTimeout}");
67+
}
68+
5269
Protocol = options.Protocol;
5370

5471
if (options.Authentication != null && !string.IsNullOrEmpty(options.Authentication.Type))

Enyim.Caching/Configuration/MemcachedClientOptions.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class MemcachedClientOptions : IOptions<MemcachedClientOptions>
1111
{
1212
public MemcachedProtocol Protocol { get; set; } = MemcachedProtocol.Binary;
1313

14-
public SocketPoolConfiguration SocketPool { get; set; } = new SocketPoolConfiguration();
14+
public SocketPoolOptions SocketPool { get; set; }
1515

1616
public List<Server> Servers { get; set; } = new List<Server>();
1717

@@ -57,4 +57,14 @@ public class Authentication
5757

5858
public Dictionary<string, string> Parameters { get; set; }
5959
}
60+
61+
public class SocketPoolOptions
62+
{
63+
public int MinPoolSize { get; set; } = 10;
64+
public int MaxPoolSize { get; set; } = 20;
65+
public TimeSpan ConnectionTimeout { get; set; } = new TimeSpan(0, 0, 10);
66+
public TimeSpan ReceiveTimeout { get; set; } = new TimeSpan(0, 0, 10);
67+
public TimeSpan DeadTimeout { get; set; } = new TimeSpan(0, 0, 10);
68+
public TimeSpan QueueTimeout { get; set; } = new TimeSpan(0, 0, 0, 0, 100);
69+
}
6070
}

Enyim.Caching/Enyim.Caching.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>EnyimMemcachedCore is a Memcached client library for .NET Core. Usage: Add services.AddEnyimMemcached(...) and app.UseEnyimMemcached() in Startup. Add IMemcachedClient into constructor.</Description>
5-
<VersionPrefix>2.0.3</VersionPrefix>
5+
<VersionPrefix>2.0.4</VersionPrefix>
66
<Authors>cnblogs.com</Authors>
77
<TargetFramework>netstandard2.0</TargetFramework>
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

SampleWebApp/Startup.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,8 @@ public Startup(IHostingEnvironment env)
3131

3232
public void ConfigureServices(IServiceCollection services)
3333
{
34-
if (IsDevelopment)
35-
{
36-
services.AddEnyimMemcached(options =>
37-
{
38-
options.AddServer("memcached", 11211);
39-
//options.AddPlainTextAuthenticator("", "usename", "password");
40-
});
41-
}
42-
else
43-
{
44-
services.AddEnyimMemcached(Configuration.GetSection("enyimMemcached"));
45-
}
46-
}
34+
services.AddEnyimMemcached(Configuration.GetSection("enyimMemcached"));
35+
}
4736

4837
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
4938
{

SampleWebApp/appsettings.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
"Address": "memcached",
66
"Port": 11211
77
}
8-
]//,
8+
],
9+
"socketPool": {
10+
"minPoolSize": "5",
11+
"maxPoolSize": "25",
12+
"connectionTimeout": "15",
13+
"receiveTimeout": "15",
14+
"deadTimeout": "15",
15+
"queueTimeout": "150"
16+
}
17+
//,
918
//"KeyTransformer": "Enyim.Caching.Memcached.SHA1KeyTransformer"
1019
//,
1120
//"Authentication": {

0 commit comments

Comments
 (0)