WebCache/RateLimit.cs
/// <summary>
/// Determines if the cache should be throttling.
/// </summary>
/// <returns></returns>
Determines if the cache should be throttling.
Determines if the cache should be throttling .
public bool IsThrottled()
        {
            long seconds = (long)TimeSpan.FromTicks(DateTime.Now.Ticks).TotalSeconds;
            long cutoff = seconds - (2 * Interval);
            var recentRequests = requestTimes.ToArray().Count(t => t > cutoff);
            bool throttled = recentRequests + 10 > Requests;
            if (!requestTimes.IsEmpty && requestTimes.Count % 20 == 0)
            {
                lock (dequeueLock)
                {
                    long removeCutoff = seconds - (2 * Interval);
                    while (true)
                    {
                        long peeked;
                        bool canPeek = requestTimes.TryPeek(out peeked);
                        if (canPeek && peeked < removeCutoff)
                        {
                            requestTimes.TryDequeue(out peeked);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            return throttled;
        }
public bool IsThrottled ( ) { long seconds = ( long ) TimeSpan . FromTicks ( DateTime . Now . Ticks ) . TotalSeconds ; long cutoff = seconds - ( 2 * Interval ) ; var recentRequests = requestTimes . ToArray ( ) . Count ( t => t > cutoff ) ; bool throttled = recentRequests + 10 > Requests ; if ( ! requestTimes . IsEmpty && requestTimes . Count % 20 == 0 ) { lock ( dequeueLock ) { long removeCutoff = seconds - ( 2 * Interval ) ; while ( true ) { long peeked ; bool canPeek = requestTimes . TryPeek ( out peeked ) ; if ( canPeek && peeked < removeCutoff ) { requestTimes . TryDequeue ( out peeked ) ; } else { break ; } } } } return throttled ; }
Determines if the cache should be throttling.
Determines if the cache should be throttling .
None