@@ -27,6 +27,7 @@ public partial class MemcachedClient : IMemcachedClient, IMemcachedResultsClient
2727 public static readonly TimeSpan Infinite = TimeSpan . Zero ;
2828 //internal static readonly MemcachedClientSection DefaultSettings = ConfigurationManager.GetSection("enyim.com/memcached") as MemcachedClientSection;
2929 private ILogger < MemcachedClient > _logger ;
30+ private bool _suppressException ;
3031
3132 private IServerPool pool ;
3233 private IMemcachedKeyTransformer keyTransformer ;
@@ -51,6 +52,7 @@ public MemcachedClient(ILoggerFactory loggerFactory, IMemcachedClientConfigurati
5152 throw new ArgumentNullException ( nameof ( configuration ) ) ;
5253 }
5354
55+ _suppressException = configuration . SuppressException ;
5456 this . keyTransformer = configuration . CreateKeyTransformer ( ) ?? new DefaultKeyTransformer ( ) ;
5557 this . transcoder = configuration . CreateTranscoder ( ) ?? new DefaultTranscoder ( ) ;
5658
@@ -154,7 +156,10 @@ public IGetOperationResult<T> PerformGet<T>(string key)
154156 }
155157 catch ( Exception ex )
156158 {
159+
157160 _logger . LogError ( 0 , ex , $ "{ nameof ( PerformGet ) } (\" { key } \" )") ;
161+ if ( ! _suppressException ) throw ;
162+
158163 result . Fail ( ex . Message ) ;
159164 return result ;
160165 }
@@ -246,6 +251,8 @@ public async Task<IGetOperationResult> GetAsync(string key)
246251 catch ( Exception ex )
247252 {
248253 _logger . LogError ( 0 , ex , $ "{ nameof ( GetAsync ) } (\" { key } \" )") ;
254+ if ( ! _suppressException ) throw ;
255+
249256 result . Fail ( ex . Message , ex ) ;
250257 return result ;
251258 }
@@ -267,6 +274,8 @@ public async Task<IGetOperationResult<T>> GetAsync<T>(string key)
267274 catch ( Exception ex )
268275 {
269276 _logger . LogError ( 0 , ex , $ "{ nameof ( GetAsync ) } (\" { key } \" )") ;
277+ if ( ! _suppressException ) throw ;
278+
270279 result . Fail ( ex . Message , ex ) ;
271280 return result ;
272281 }
@@ -300,6 +309,7 @@ public async Task<T> GetValueOrCreateAsync<T>(string key, int cacheSeconds, Func
300309 catch ( Exception ex )
301310 {
302311 _logger . LogError ( ex , $ "{ nameof ( AddAsync ) } (\" { key } \" , ..., { cacheSeconds } )") ;
312+ if ( ! _suppressException ) throw ;
303313 }
304314 }
305315 return value ;
@@ -594,6 +604,7 @@ protected virtual IStoreOperationResult PerformStore(StoreMode mode, string key,
594604 catch ( Exception e )
595605 {
596606 _logger . LogError ( "PerformStore" , e ) ;
607+ if ( ! _suppressException ) throw ;
597608
598609 result . Fail ( "PerformStore failed" , e ) ;
599610 return result ;
@@ -1221,6 +1232,7 @@ protected virtual IDictionary<string, T> PerformMultiGet<T>(IEnumerable<string>
12211232 catch ( Exception e )
12221233 {
12231234 _logger . LogError ( 0 , e , "PerformMultiGet" ) ;
1235+ if ( ! _suppressException ) throw ;
12241236 }
12251237 } ) ) ;
12261238 }
0 commit comments