@@ -17,11 +17,13 @@ namespace Enyim.Caching.Configuration
17
17
/// </summary>
18
18
public class MemcachedClientConfiguration : IMemcachedClientConfiguration
19
19
{
20
- // these are lazy initialized in the getters
20
+ private readonly bool _useLegacyNodeLocator ;
21
+ private readonly ILogger < MemcachedClientConfiguration > _logger ;
22
+
21
23
private Type _nodeLocator ;
22
24
private ITranscoder _transcoder ;
23
25
private IMemcachedKeyTransformer _keyTransformer ;
24
- private ILogger < MemcachedClientConfiguration > _logger ;
26
+
25
27
26
28
/// <summary>
27
29
/// Initializes a new instance of the <see cref="T:MemcachedClientConfiguration"/> class.
@@ -153,18 +155,10 @@ public MemcachedClientConfiguration(
153
155
_logger . LogDebug ( $ "Use KeyTransformer Type : '{ keyTransformer } '") ;
154
156
}
155
157
158
+ _useLegacyNodeLocator = options . UseLegacyNodeLocator ;
156
159
if ( NodeLocator == null )
157
160
{
158
- if ( options . Servers . Count > 1 )
159
- {
160
- NodeLocator = options . UseLegacyNodeLocator ? typeof ( LegacyNodeLocator ) : typeof ( DefaultNodeLocator ) ;
161
- }
162
- else
163
- {
164
- NodeLocator = typeof ( SingleNodeLocator ) ;
165
- }
166
-
167
- _logger . LogDebug ( $ "Use NodeLocator: { NodeLocator } ") ;
161
+ SetNodeLocator ( ) ;
168
162
}
169
163
170
164
if ( ! string . IsNullOrEmpty ( options . Transcoder ) )
@@ -217,7 +211,7 @@ private void ConfigureServers(MemcachedClientOptions options)
217
211
{
218
212
if ( IPAddress . TryParse ( server . Address , out var address ) )
219
213
{
220
- Servers . Add ( new IPEndPoint ( address , server . Port ) ) ;
214
+ AddServer ( address , server . Port ) ;
221
215
}
222
216
else
223
217
{
@@ -229,23 +223,50 @@ private void ConfigureServers(MemcachedClientOptions options)
229
223
}
230
224
}
231
225
226
+ private void SetNodeLocator ( )
227
+ {
228
+ if ( Servers . Count > 1 )
229
+ {
230
+ NodeLocator = _useLegacyNodeLocator ? typeof ( LegacyNodeLocator ) : typeof ( DefaultNodeLocator ) ;
231
+ }
232
+ else
233
+ {
234
+ NodeLocator = typeof ( SingleNodeLocator ) ;
235
+ }
236
+
237
+ _logger . LogDebug ( "Use NodeLocator: {NodeLocator}" , NodeLocator ) ;
238
+ }
239
+
232
240
/// <summary>
233
241
/// Adds a new server to the pool.
234
242
/// </summary>
235
243
/// <param name="address">The address and the port of the server in the format 'host:port'.</param>
236
244
public void AddServer ( string address )
237
245
{
238
246
Servers . Add ( ConfigurationHelper . ResolveToEndPoint ( address ) ) ;
247
+ SetNodeLocator ( ) ;
239
248
}
240
249
241
250
/// <summary>
242
251
/// Adds a new server to the pool.
243
252
/// </summary>
244
- /// <param name="address">The host name or IP address of the server .</param>
253
+ /// <param name="address">The host name.</param>
245
254
/// <param name="port">The port number of the memcached instance.</param>
246
255
public void AddServer ( string host , int port )
247
256
{
248
257
Servers . Add ( new DnsEndPoint ( host , port ) ) ;
258
+ SetNodeLocator ( ) ;
259
+ }
260
+
261
+ /// <summary>
262
+ /// Adds a new server to the pool.
263
+ /// </summary>
264
+ /// <param name="ip">The IP address of the server.</param>
265
+ /// <param name="port">The port number of the memcached instance.</param>
266
+ public void AddServer ( IPAddress ip , int port )
267
+ {
268
+ Servers . Add ( new IPEndPoint ( ip , port ) ) ;
269
+ SetNodeLocator ( ) ;
249
270
}
250
271
251
272
/// <summary>
0 commit comments