private OnException ( |
||
sender | ||
e | ExceptionEventArgs | |
return | void |
/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="value"></param> public void Put(object key, object value) { key.ThrowIfNull("key"); value.ThrowIfNull("value"); Log.Debug("put in cache: regionName='{0}', key='{1}'", RegionName, key); try { var serializedValue = _options.Serializer.Serialize(value); var cacheKey = CacheNamespace.GetKey(key); var setOfActiveKeysKey = CacheNamespace.GetSetOfActiveKeysKey(); var db = GetDatabase(); //TODO 临时不处理,这里缓存了实体 db.ScriptEvaluate(PutScript, new { key = cacheKey, setOfActiveKeysKey = setOfActiveKeysKey, value = serializedValue, expiration = _expiration.TotalMilliseconds }, FireAndForgetFlags); } catch (Exception e) { Log.Error("could not put in cache: regionName='{0}', key='{1}'", RegionName, key); var evtArg = new ExceptionEventArgs(RegionName, RedisCacheMethod.Put, e); _options.OnException(this, evtArg); if (evtArg.Throw) { throw new RedisCacheException(RegionName, "Failed to put item in cache. See inner exception.", e); } } }
private async Task PutCoreAsync(object key, object value, CancellationToken cancellationToken, bool sync = false) { key.ThrowIfNull("key"); value.ThrowIfNull("value"); cancellationToken.ThrowIfNull("cancellationToken"); if (cancellationToken.IsCancellationRequested) { return; } log.Debug("put in cache: regionName='{0}', key='{1}'", RegionName, key); try { var serializedValue = options.Serializer.Serialize(value); var cacheKey = CacheNamespace.GetKey(key); var setOfActiveKeysKey = CacheNamespace.GetSetOfActiveKeysKey(); var db = GetDatabase(); var args = new { key = cacheKey, setOfActiveKeysKey = setOfActiveKeysKey, value = serializedValue, expiration = expiration.TotalMilliseconds }; if (sync) { db.ScriptEvaluate(putScript, args, fireAndForgetFlags); } else { await db.ScriptEvaluateAsync(putScript, args, fireAndForgetFlags); } } catch (Exception e) { log.Error("could not put in cache: regionName='{0}', key='{1}'", RegionName, key); var evtArg = new ExceptionEventArgs(RegionName, RedisCacheMethod.Put, e); options.OnException(this, evtArg); if (evtArg.Throw) { throw new RedisCacheException(RegionName, "Failed to put item in cache. See inner exception.", e); } } }
/// <summary> /// 到redis 不可用是,处理redis 请求 /// </summary> /// <param name="configuration"></param> /// <param name="properties"></param> /// <param name="connectionMultiplexer"></param> /// <param name="options"></param> /// <returns></returns> protected override RedisCache BuildCache(RedisCacheConfiguration configuration, IDictionary <string, string> properties, ConnectionMultiplexer connectionMultiplexer, RedisCacheProviderOptions options) { //options.OnException = (e) => //{ // if (HttpContext.Current != null) // { // HttpContext.Current.Items[RequestRecoveryRedisCache.SkipNHibernateCacheKey] = true; // } // else // { // CallContext.SetData(RequestRecoveryRedisCache.SkipNHibernateCacheKey, true); // } //}; //var evtArg = new ExceptionEventArgs(configuration.RegionName, RedisCacheMethod.Clear, e); //options.OnException(this, evtArg); options.OnException(null, new ExceptionEventArgs(configuration.RegionName, RedisCacheMethod.Unknown, new Exception())); return(new RequestRecoveryRedisCache(configuration, properties, connectionMultiplexer, options)); }
private void OnException(RedisCacheExceptionEventArgs e) { options.OnException(e); }