Class: Phronomy::StateStore::InMemory
- Defined in:
- lib/phronomy/state_store/in_memory.rb
Overview
In-memory state store. Stores state objects keyed by thread_id. State objects are stored directly (no serialization), so this backend is suitable for single-process use only.
Instance Method Summary collapse
- #clear(thread_id) ⇒ self
- #clear_all ⇒ Object
-
#initialize ⇒ InMemory
constructor
A new instance of InMemory.
-
#load(thread_id) ⇒ Object?
State object or nil.
- #save(state) ⇒ self
Constructor Details
#initialize ⇒ InMemory
Returns a new instance of InMemory.
9 10 11 12 |
# File 'lib/phronomy/state_store/in_memory.rb', line 9 def initialize @store = {} @mutex = Mutex.new end |
Instance Method Details
#clear(thread_id) ⇒ self
29 30 31 32 |
# File 'lib/phronomy/state_store/in_memory.rb', line 29 def clear(thread_id) @mutex.synchronize { @store.delete(thread_id) } self end |
#clear_all ⇒ Object
34 35 36 37 |
# File 'lib/phronomy/state_store/in_memory.rb', line 34 def clear_all @mutex.synchronize { @store.clear } self end |
#load(thread_id) ⇒ Object?
Returns state object or nil.
23 24 25 |
# File 'lib/phronomy/state_store/in_memory.rb', line 23 def load(thread_id) @mutex.synchronize { @store[thread_id] } end |
#save(state) ⇒ self
16 17 18 19 |
# File 'lib/phronomy/state_store/in_memory.rb', line 16 def save(state) @mutex.synchronize { @store[state.thread_id] = state } self end |