Skip to content

Commit d5208ef

Browse files
committed
Merge pull request #24 from jbattermann/master
Added MemcachedClientCache.ctor() that takes an IMemcachedClientConfiguration instance
2 parents 90c0238 + e2875b8 commit d5208ef

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

src/ServiceStack.CacheAccess.Memcached/MemcachedClientCache.cs

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,49 @@ public MemcachedClientCache(IEnumerable<string> hosts)
5757
ipEndpoints.Add(endpoint);
5858
}
5959
}
60-
LoadClient(ipEndpoints);
60+
61+
LoadClient(PrepareMemcachedClientConfiguration(ipEndpoints));
6162
}
6263

6364
public MemcachedClientCache(IEnumerable<IPEndPoint> ipEndpoints)
6465
{
65-
LoadClient(ipEndpoints);
66+
LoadClient(PrepareMemcachedClientConfiguration(ipEndpoints));
6667
}
6768

68-
private void LoadClient(IEnumerable<IPEndPoint> ipEndpoints)
69-
{
70-
Enyim.Caching.LogManager.AssignFactory(new EnyimLogFactoryWrapper());
69+
/// <summary>
70+
/// Initializes a new instance of the <see cref="MemcachedClientCache"/> class based on an existing <see cref="IMemcachedClientConfiguration"/>.
71+
/// </summary>
72+
/// <param name="memcachedClientConfiguration">The <see cref="IMemcachedClientConfiguration"/>.</param>
73+
public MemcachedClientCache(IMemcachedClientConfiguration memcachedClientConfiguration)
74+
{
75+
LoadClient(memcachedClientConfiguration);
76+
}
7177

72-
var config = new MemcachedClientConfiguration();
73-
foreach (var ipEndpoint in ipEndpoints)
74-
{
75-
config.Servers.Add(ipEndpoint);
76-
}
78+
/// <summary>
79+
/// Prepares a MemcachedClientConfiguration based on the provided ipEndpoints.
80+
/// </summary>
81+
/// <param name="ipEndpoints">The ip endpoints.</param>
82+
/// <returns></returns>
83+
private IMemcachedClientConfiguration PrepareMemcachedClientConfiguration(IEnumerable<IPEndPoint> ipEndpoints)
84+
{
85+
var config = new MemcachedClientConfiguration();
86+
foreach (var ipEndpoint in ipEndpoints)
87+
{
88+
config.Servers.Add(ipEndpoint);
89+
}
90+
91+
config.SocketPool.MinPoolSize = 10;
92+
config.SocketPool.MaxPoolSize = 100;
93+
config.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 10);
94+
config.SocketPool.DeadTimeout = new TimeSpan(0, 2, 0);
7795

78-
config.SocketPool.MinPoolSize = 10;
79-
config.SocketPool.MaxPoolSize = 100;
80-
config.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 10);
81-
config.SocketPool.DeadTimeout = new TimeSpan(0, 2, 0);
96+
return config;
97+
}
8298

99+
private void LoadClient(IMemcachedClientConfiguration config)
100+
{
101+
Enyim.Caching.LogManager.AssignFactory(new EnyimLogFactoryWrapper());
102+
83103
_client = new MemcachedClient(config);
84104
}
85105

@@ -107,7 +127,6 @@ public object Get(string key)
107127

108128
public object Get(string key, out ulong ucas)
109129
{
110-
IDictionary<string, ulong> casValues;
111130
var result = _client.GetWithCas<MemcachedValueWrapper>(key);
112131
if (result.Result != null)
113132
{

0 commit comments

Comments
 (0)