Module: Philiprehberger::RateLimiter
- Defined in:
- lib/philiprehberger/rate_limiter.rb,
lib/philiprehberger/rate_limiter/noop.rb,
lib/philiprehberger/rate_limiter/version.rb,
lib/philiprehberger/rate_limiter/fixed_window.rb,
lib/philiprehberger/rate_limiter/token_bucket.rb,
lib/philiprehberger/rate_limiter/sliding_window.rb,
lib/philiprehberger/rate_limiter/stats_tracking.rb
Defined Under Namespace
Modules: StatsTracking Classes: Error, FixedWindow, Noop, RateLimitExceeded, SlidingWindow, TokenBucket
Constant Summary collapse
- VERSION =
'0.13.0'
Class Method Summary collapse
-
.fixed_window(limit:, window:) ⇒ FixedWindow
Build a fixed-window limiter: an O(1)-per-key counter that resets when the window elapses.
-
.noop ⇒ Noop
Build a no-op limiter that always allows requests.
- .sliding_window(limit:, window:, max_keys: nil) ⇒ Object
- .token_bucket(rate:, capacity:, max_keys: nil) ⇒ Object
Class Method Details
.fixed_window(limit:, window:) ⇒ FixedWindow
Build a fixed-window limiter: an O(1)-per-key counter that resets when the window elapses.
37 38 39 |
# File 'lib/philiprehberger/rate_limiter.rb', line 37 def self.fixed_window(limit:, window:) FixedWindow.new(limit: limit, window: window) end |
.noop ⇒ Noop
Build a no-op limiter that always allows requests.
44 45 46 |
# File 'lib/philiprehberger/rate_limiter.rb', line 44 def self.noop Noop.new end |
.sliding_window(limit:, window:, max_keys: nil) ⇒ Object
25 26 27 |
# File 'lib/philiprehberger/rate_limiter.rb', line 25 def self.sliding_window(limit:, window:, max_keys: nil) SlidingWindow.new(limit: limit, window: window, max_keys: max_keys) end |
.token_bucket(rate:, capacity:, max_keys: nil) ⇒ Object
29 30 31 |
# File 'lib/philiprehberger/rate_limiter.rb', line 29 def self.token_bucket(rate:, capacity:, max_keys: nil) TokenBucket.new(rate: rate, capacity: capacity, max_keys: max_keys) end |