2 def initialize(cache, interval, limit, max_burst)
4 @requests_per_second = limit.to_f / interval
5 @burst_limit = max_burst
9 last_update, requests = @cache.get(key)
12 elapsed = Time.now.to_i - last_update
14 requests -= elapsed * @requests_per_second
19 requests < @burst_limit
25 last_update, requests = @cache.get(key)
28 elapsed = now - last_update
30 requests -= elapsed * @requests_per_second
36 @cache.set(key, [now, [requests, 1.0].max])