public static bool Check(ThrottleLimit limit) { var cache = HostingEnvironment.Cache; var cacheKey = limit.CacheKey; var hit = (HitInfo)(cache[cacheKey]); if (hit == null) { hit = new HitInfo { Counter = 1 }; cache.Add(cacheKey, hit, null, DateTime.Now.Add(limit.Duration), Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.BelowNormal, null); } else { if (hit.Counter++ > limit.Limit) { return(false); } } return(true); }
public static bool Check(ThrottleLimit limit) { var cache = HostingEnvironment.Cache; var cacheKey = limit.CacheKey; var hit = (HitInfo)(cache[cacheKey]); if (hit == null) { hit = new HitInfo { Counter = 1 }; cache.Add(cacheKey, hit, null, DateTime.Now.Add(limit.Duration), Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.BelowNormal, null); } else { if (hit.Counter++ > limit.Limit) return false; } return true; }