diff --git a/Enyim.Caching/Configuration/IMemcachedClientConfiguration.cs b/Enyim.Caching/Configuration/IMemcachedClientConfiguration.cs index 2951d33e..6463908b 100755 --- a/Enyim.Caching/Configuration/IMemcachedClientConfiguration.cs +++ b/Enyim.Caching/Configuration/IMemcachedClientConfiguration.cs @@ -42,8 +42,9 @@ public interface IMemcachedClientConfiguration IServerPool CreatePool(); - bool UseSslStream { get; } + bool UseSslStream { get; } + bool SuppressException { get; } } } diff --git a/Enyim.Caching/Configuration/MemcachedClientConfiguration.cs b/Enyim.Caching/Configuration/MemcachedClientConfiguration.cs index d28b9504..74e4c8ba 100755 --- a/Enyim.Caching/Configuration/MemcachedClientConfiguration.cs +++ b/Enyim.Caching/Configuration/MemcachedClientConfiguration.cs @@ -117,6 +117,7 @@ public MemcachedClientConfiguration( } UseSslStream = options.UseSslStream; + SuppressException = options.SuppressException; if (!string.IsNullOrEmpty(options.KeyTransformer)) { @@ -203,7 +204,7 @@ private void ConfigureServers(MemcachedClientOptions options) } else { - _logger.LogInformation($"Memcached server address - {server.Address }:{server.Port}"); + _logger.LogInformation($"Memcached server address - {server.Address}:{server.Port}"); } Servers.Add(new IPEndPoint(address, server.Port)); @@ -338,6 +339,8 @@ IServerPool IMemcachedClientConfiguration.CreatePool() public bool UseSslStream { get; private set; } + public bool SuppressException { get; private set; } + #endregion } } diff --git a/Enyim.Caching/Configuration/MemcachedClientOptions.cs b/Enyim.Caching/Configuration/MemcachedClientOptions.cs index 4f58ab85..3c265755 100644 --- a/Enyim.Caching/Configuration/MemcachedClientOptions.cs +++ b/Enyim.Caching/Configuration/MemcachedClientOptions.cs @@ -23,6 +23,8 @@ public class MemcachedClientOptions : IOptions public bool UseSslStream { get; set; } + public bool SuppressException { get; set; } = true; + public IProviderFactory NodeLocatorFactory { get; set; } public MemcachedClientOptions Value => this; diff --git a/Enyim.Caching/MemcachedClient.cs b/Enyim.Caching/MemcachedClient.cs index 3447b644..7f3ae407 100755 --- a/Enyim.Caching/MemcachedClient.cs +++ b/Enyim.Caching/MemcachedClient.cs @@ -27,6 +27,7 @@ public partial class MemcachedClient : IMemcachedClient, IMemcachedResultsClient public static readonly TimeSpan Infinite = TimeSpan.Zero; //internal static readonly MemcachedClientSection DefaultSettings = ConfigurationManager.GetSection("enyim.com/memcached") as MemcachedClientSection; private ILogger _logger; + private bool _suppressException; private IServerPool pool; private IMemcachedKeyTransformer keyTransformer; @@ -51,6 +52,7 @@ public MemcachedClient(ILoggerFactory loggerFactory, IMemcachedClientConfigurati throw new ArgumentNullException(nameof(configuration)); } + _suppressException = configuration.SuppressException; this.keyTransformer = configuration.CreateKeyTransformer() ?? new DefaultKeyTransformer(); this.transcoder = configuration.CreateTranscoder() ?? new DefaultTranscoder(); @@ -154,7 +156,10 @@ public IGetOperationResult PerformGet(string key) } catch (Exception ex) { + _logger.LogError(0, ex, $"{nameof(PerformGet)}(\"{key}\")"); + if (!_suppressException) throw; + result.Fail(ex.Message); return result; } @@ -246,6 +251,8 @@ public async Task GetAsync(string key) catch (Exception ex) { _logger.LogError(0, ex, $"{nameof(GetAsync)}(\"{key}\")"); + if (!_suppressException) throw; + result.Fail(ex.Message, ex); return result; } @@ -267,6 +274,8 @@ public async Task> GetAsync(string key) catch (Exception ex) { _logger.LogError(0, ex, $"{nameof(GetAsync)}(\"{key}\")"); + if (!_suppressException) throw; + result.Fail(ex.Message, ex); return result; } @@ -300,6 +309,7 @@ public async Task GetValueOrCreateAsync(string key, int cacheSeconds, Func catch (Exception ex) { _logger.LogError(ex, $"{nameof(AddAsync)}(\"{key}\", ..., {cacheSeconds})"); + if (!_suppressException) throw; } } return value; @@ -594,6 +604,7 @@ protected virtual IStoreOperationResult PerformStore(StoreMode mode, string key, catch (Exception e) { _logger.LogError("PerformStore", e); + if (!_suppressException) throw; result.Fail("PerformStore failed", e); return result; @@ -1221,6 +1232,7 @@ protected virtual IDictionary PerformMultiGet(IEnumerable catch (Exception e) { _logger.LogError(0, e, "PerformMultiGet"); + if (!_suppressException) throw; } })); } diff --git a/SampleWebApp/appsettings.json b/SampleWebApp/appsettings.json index ca64a6dd..779a1395 100644 --- a/SampleWebApp/appsettings.json +++ b/SampleWebApp/appsettings.json @@ -13,7 +13,8 @@ "receiveTimeout": "00:00:15", "deadTimeout": "00:00:15", "queueTimeout": "00:00:00.150" - } //, + }, + "suppressException": "false" //"Transcoder": "BinaryFormatterTranscoder" //, //"KeyTransformer": "Enyim.Caching.Memcached.SHA1KeyTransformer"