Class: Notion::Middleware::RateLimiter::MemoryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/notion/middleware/rate_limiter.rb

Instance Method Summary collapse

Constructor Details

#initializeMemoryStore

Returns a new instance of MemoryStore.



9
10
11
12
# File 'lib/notion/middleware/rate_limiter.rb', line 9

def initialize
  @states = {}
  @mutex = Mutex.new
end

Instance Method Details

#state(key, burst, now) ⇒ Object



14
15
16
17
18
# File 'lib/notion/middleware/rate_limiter.rb', line 14

def state(key, burst, now)
  return State.new(burst, now, now, Mutex.new) unless key

  @mutex.synchronize { @states[key] ||= State.new(burst, now, now, Mutex.new) }
end