/// <summary> /// Performs the invalidation if the request has an <see cref="InvalidateCachedInstancesOfAttribute"/> attribute. /// </summary> public void Intercept(IColomboRequestHandleInvocation nextInvocation) { var invalidateCachedInstancesOfAttributes = nextInvocation.Request.GetCustomAttributes<InvalidateCachedInstancesOfAttribute>(); foreach (var invalidateCachedInstancesOfAttribute in invalidateCachedInstancesOfAttributes) { foreach (var responseType in invalidateCachedInstancesOfAttribute.ResponsesTypes) { string cacheSegment = null; var cacheSegmentAttribute = nextInvocation.Request.GetCustomAttribute<CacheSegmentAttribute>(); if (cacheSegmentAttribute != null) cacheSegment = cacheSegmentAttribute.GetCacheSegment(nextInvocation.Request); Logger.DebugFormat("Invalidating all responses of type {0} from cache segment {1}", responseType, cacheSegment); cache.Flush(cacheSegment, responseType); } } nextInvocation.Proceed(); var enableClientCachingAttribute = nextInvocation.Request.GetCustomAttribute<EnableCacheAttribute>(); if (enableClientCachingAttribute == null) return; var cacheKey = nextInvocation.Request.GetCacheKey(); string cacheSegmentAfter = null; var cacheSegmentAttributeAfter = nextInvocation.Request.GetCustomAttribute<CacheSegmentAttribute>(); if (cacheSegmentAttributeAfter != null) cacheSegmentAfter = cacheSegmentAttributeAfter.GetCacheSegment(nextInvocation.Request); Logger.DebugFormat("Caching {0} in segment {1} with cacheKey {2} for {3}", nextInvocation.Request, cacheSegmentAfter, cacheKey, enableClientCachingAttribute.Duration); cache.Store(cacheSegmentAfter, cacheKey, nextInvocation.Response, enableClientCachingAttribute.Duration); }
/// <summary> /// Monitor the performance. /// </summary> public void Intercept(IColomboRequestHandleInvocation invocation) { if (invocation == null) throw new ArgumentNullException("invocation"); Contract.EndContractBlock(); var watch = new Stopwatch(); watch.Start(); invocation.Proceed(); watch.Stop(); try { var instanceName = invocation.Request.GetGroupName(); using (var numberOfRequestsHandled = PerfCounterFactory.GetPerfCounter(PerfCounter.NumRequestsHandled, instanceName)) numberOfRequestsHandled.Increment(); using (var numberOfRequestsHandledPerSec = PerfCounterFactory.GetPerfCounter(PerfCounter.NumRequestsHandledPerSec, instanceName)) numberOfRequestsHandledPerSec.Increment(); using (var averageDurationForRequestHandling = PerfCounterFactory.GetPerfCounter(PerfCounter.AverageDurationForRequestHandling, instanceName)) averageDurationForRequestHandling.IncrementBy(watch.ElapsedTicks); using (var averageDurationForRequestHandlingBase = PerfCounterFactory.GetPerfCounter(PerfCounter.AverageDurationForRequestHandlingBase, instanceName)) averageDurationForRequestHandlingBase.Increment(); } catch (Exception ex) { Logger.Warn("Error while computing performance counters values.", ex); } }
public void Intercept(IColomboRequestHandleInvocation nextInvocation) { try { nextInvocation.Proceed(); } catch (Exception ex) { try { var alert = new ExceptionAlert(new[] { nextInvocation.Request }, ex); Logger.Warn(alert.ToString()); foreach (var alerter in Alerters) alerter.Alert(alert); } catch { } throw; } }