public bool IsLocked(IThrottleKey key, out CheckResult result, bool increment = true) { result = Check(key, increment); return result.IsLocked; }
public CheckResult Check(IThrottleKey key, bool increment = true) { foreach (Limiter limiter in Limiters) { var result = new CheckResult { IsThrottled = false, IsLocked = false, ThrottleKey = _repository.CreateThrottleKey(key, limiter), Limiter = limiter }; if (limiter.LockDuration.HasValue) { result.LockKey = _repository.CreateLockKey(key, limiter); if (_repository.LockExists(key, limiter)) { result.IsLocked = true; return result; } } // Short-circuit this loop if the // limit value isn't valid if (limiter.Count <= 0) continue; long? counter = _repository.GetThrottleCount(key, limiter); if (counter.HasValue && counter.Value >= limiter.Count) { if (limiter.LockDuration.HasValue) { _repository.SetLock(key, limiter); _repository.RemoveThrottle(key, limiter); } result.IsThrottled = true; return result; } if (increment) _repository.AddOrIncrementWithExpiration(key, limiter); } return CheckResult.NotThrottled; }
public bool IsLocked(IThrottleKey key, out CheckResult result, bool increment = true) { result = Check(key, increment); return(result.IsLocked); }