Class: Phronomy::StateStore::InMemory

Inherits:
Base
  • Object
show all
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

Constructor Details

#initializeInMemory

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

Parameters:

  • thread_id (String)

Returns:

  • (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_allObject



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.

Parameters:

  • thread_id (String)

Returns:

  • (Object, nil)

    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

Parameters:

  • state (Object)

    includes Phronomy::Graph::State; must have a non-nil thread_id

Returns:

  • (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