Class: ResilientCall::Storage::Memory
- Defined in:
- lib/resilient_call/storage/memory.rb
Overview
Default storage: keeps circuit state in a Hash in the current process. Thread-safe on its own operations via an internal Mutex. State is not shared across processes — use Storage::Redis for multi-worker setups.
Instance Method Summary collapse
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #read(circuit_name) ⇒ Object
- #reset(circuit_name) ⇒ Object
- #reset_all ⇒ Object
- #write(circuit_name, state) ⇒ Object
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
11 12 13 14 |
# File 'lib/resilient_call/storage/memory.rb', line 11 def initialize @data = {} @mutex = Mutex.new end |
Instance Method Details
#read(circuit_name) ⇒ Object
16 17 18 |
# File 'lib/resilient_call/storage/memory.rb', line 16 def read(circuit_name) @mutex.synchronize { @data[circuit_name] } end |
#reset(circuit_name) ⇒ Object
24 25 26 |
# File 'lib/resilient_call/storage/memory.rb', line 24 def reset(circuit_name) @mutex.synchronize { @data.delete(circuit_name) } end |
#reset_all ⇒ Object
28 29 30 |
# File 'lib/resilient_call/storage/memory.rb', line 28 def reset_all @mutex.synchronize { @data.clear } end |
#write(circuit_name, state) ⇒ Object
20 21 22 |
# File 'lib/resilient_call/storage/memory.rb', line 20 def write(circuit_name, state) @mutex.synchronize { @data[circuit_name] = state } end |