Class: Phronomy::StateStore::InMemory
- Defined in:
- lib/phronomy/state_store/in_memory.rb
Overview
In-memory state store backed by per-thread-id Actor instances from ThreadActorRegistry. Suitable for single-process use only.
Constant Summary collapse
- THREAD_DATA_KEY =
Thread-local key for per-thread-id state data (namespaced by store instance object_id to support multiple independent InMemory stores).
:phronomy_state_store_in_memory_data
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.
12 13 |
# File 'lib/phronomy/state_store/in_memory.rb', line 12 def initialize end |
Instance Method Details
#clear(thread_id) ⇒ self
36 37 38 39 40 41 42 |
# File 'lib/phronomy/state_store/in_memory.rb', line 36 def clear(thread_id) store_id = object_id Phronomy::ThreadActorRegistry.for(thread_id).call do (Thread.current[THREAD_DATA_KEY] ||= {}).delete(store_id) end self end |
#clear_all ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/phronomy/state_store/in_memory.rb', line 44 def clear_all store_id = object_id Phronomy::ThreadActorRegistry.each_actor do |actor| actor.call { (Thread.current[THREAD_DATA_KEY] ||= {}).delete(store_id) } end self end |
#load(thread_id) ⇒ Object?
Returns state object or nil.
27 28 29 30 31 32 |
# File 'lib/phronomy/state_store/in_memory.rb', line 27 def load(thread_id) store_id = object_id Phronomy::ThreadActorRegistry.for(thread_id).call do (Thread.current[THREAD_DATA_KEY] ||= {})[store_id] end end |
#save(state) ⇒ self
17 18 19 20 21 22 23 |
# File 'lib/phronomy/state_store/in_memory.rb', line 17 def save(state) store_id = object_id Phronomy::ThreadActorRegistry.for(state.thread_id).call do (Thread.current[THREAD_DATA_KEY] ||= {})[store_id] = state end self end |