Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions src/Enyim.Caching/Configuration/MemcachedClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ namespace Enyim.Caching.Configuration
/// </summary>
public class MemcachedClientConfiguration : IMemcachedClientConfiguration
{
// these are lazy initialized in the getters
private readonly bool _useLegacyNodeLocator;
private readonly ILogger<MemcachedClientConfiguration> _logger;

private Type _nodeLocator;
private ITranscoder _transcoder;
private IMemcachedKeyTransformer _keyTransformer;
private ILogger<MemcachedClientConfiguration> _logger;


/// <summary>
/// Initializes a new instance of the <see cref="T:MemcachedClientConfiguration"/> class.
Expand Down Expand Up @@ -153,18 +155,10 @@ public MemcachedClientConfiguration(
_logger.LogDebug($"Use KeyTransformer Type : '{keyTransformer}'");
}

_useLegacyNodeLocator = options.UseLegacyNodeLocator;
if (NodeLocator == null)
{
if (options.Servers.Count > 1)
{
NodeLocator = options.UseLegacyNodeLocator ? typeof(LegacyNodeLocator) : typeof(DefaultNodeLocator);
}
else
{
NodeLocator = typeof(SingleNodeLocator);
}

_logger.LogDebug($"Use NodeLocator: {NodeLocator}");
SetNodeLocator();
}

if (!string.IsNullOrEmpty(options.Transcoder))
Expand Down Expand Up @@ -217,7 +211,7 @@ private void ConfigureServers(MemcachedClientOptions options)
{
if (IPAddress.TryParse(server.Address, out var address))
{
Servers.Add(new IPEndPoint(address, server.Port));
AddServer(address, server.Port);
}
else
{
Expand All @@ -229,23 +223,50 @@ private void ConfigureServers(MemcachedClientOptions options)
}
}

private void SetNodeLocator()
{
if (Servers.Count > 1)
{
NodeLocator = _useLegacyNodeLocator ? typeof(LegacyNodeLocator) : typeof(DefaultNodeLocator);
}
else
{
NodeLocator = typeof(SingleNodeLocator);
}

_logger.LogDebug("Use NodeLocator: {NodeLocator}", NodeLocator);
}

/// <summary>
/// Adds a new server to the pool.
/// </summary>
/// <param name="address">The address and the port of the server in the format 'host:port'.</param>
public void AddServer(string address)
{
Servers.Add(ConfigurationHelper.ResolveToEndPoint(address));
SetNodeLocator();
}

/// <summary>
/// Adds a new server to the pool.
/// </summary>
/// <param name="address">The host name or IP address of the server.</param>
/// <param name="address">The host name.</param>
/// <param name="port">The port number of the memcached instance.</param>
public void AddServer(string host, int port)
{
Servers.Add(new DnsEndPoint(host, port));
SetNodeLocator();
}

/// <summary>
/// Adds a new server to the pool.
/// </summary>
/// <param name="ip">The IP address of the server.</param>
/// <param name="port">The port number of the memcached instance.</param>
public void AddServer(IPAddress ip, int port)
{
Servers.Add(new IPEndPoint(ip, port));
SetNodeLocator();
}

/// <summary>
Expand Down
Loading