2
2
{
3
3
using EasyCaching . Core ;
4
4
using EasyCaching . Core . DistributedLock ;
5
- using EasyCaching . Memcached . DistributedLock ;
5
+ using EasyCaching . Memcached . DistributedLock ;
6
6
using Microsoft . Extensions . Logging ;
7
7
using System ;
8
8
using System . Collections . Generic ;
@@ -157,9 +157,9 @@ public override CacheValue<T> BaseGet<T>(string cacheKey)
157
157
{
158
158
ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
159
159
160
- var data = _memcachedClient . PerformGet < T > ( this . HandleCacheKey ( cacheKey ) ) ;
160
+ var data = _memcachedClient . PerformGet < object > ( this . HandleCacheKey ( cacheKey ) ) ;
161
161
162
- if ( ! data . Success ) throw new EasyCachingException ( $ "opereation fail { data . Message } " , data . Exception ) ;
162
+ CheckResult ( data ) ;
163
163
164
164
var result = ConvertFromStoredValue < T > ( data . Value ) ;
165
165
@@ -186,7 +186,7 @@ public override void BaseRemove(string cacheKey)
186
186
187
187
var data = _memcachedClient . ExecuteRemove ( this . HandleCacheKey ( cacheKey ) ) ;
188
188
189
- if ( ! data . Success ) throw new EasyCachingException ( $ "opereation fail { data . Message } " , data . Exception ) ;
189
+ CheckResult ( data ) ;
190
190
}
191
191
192
192
/// <summary>
@@ -215,7 +215,7 @@ public override void BaseSet<T>(string cacheKey, T cacheValue, TimeSpan expirati
215
215
this . ConvertToStoredValue ( cacheValue ) ,
216
216
expiration ) ;
217
217
218
- if ( ! data . Success ) throw new EasyCachingException ( $ "opereation fail { data . Message } " , data . Exception ) ;
218
+ CheckResult ( data ) ;
219
219
}
220
220
221
221
/// <summary>
@@ -261,7 +261,7 @@ public override void BaseRemoveByPrefix(string prefix)
261
261
newValue ,
262
262
new TimeSpan ( 0 , 0 , 0 ) ) ;
263
263
264
- if ( ! data . Success ) throw new EasyCachingException ( $ "opereation fail { data . Message } " , data . Exception ) ;
264
+ CheckResult ( data ) ;
265
265
}
266
266
267
267
/// <summary>
@@ -442,5 +442,13 @@ private void OnCacheMiss(string cacheKey)
442
442
if ( _options . EnableLogging )
443
443
_logger ? . LogInformation ( $ "Cache Missed : cachekey = { cacheKey } ") ;
444
444
}
445
+
446
+ private void CheckResult ( Enyim . Caching . Memcached . Results . IOperationResult data )
447
+ {
448
+ if ( ! data . Success
449
+ && ( ! data . InnerResult ? . Success ?? false )
450
+ && ( data . InnerResult ? . Message ? . Contains ( "Failed to create socket" ) ?? false ) )
451
+ throw new EasyCachingException ( $ "opereation fail, { data . InnerResult ? . Message ?? "" } ", data . Exception ) ;
452
+ }
445
453
}
446
454
}
0 commit comments