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
# File 'lib/phronomy/state_store/in_memory.rb', line 9

def initialize
  @store = {}
end

Instance Method Details

#clear(thread_id) ⇒ self

Parameters:

  • thread_id (String)

Returns:

  • (self)


28
29
30
31
# File 'lib/phronomy/state_store/in_memory.rb', line 28

def clear(thread_id)
  @store.delete(thread_id)
  self
end

#clear_allObject



33
34
35
36
# File 'lib/phronomy/state_store/in_memory.rb', line 33

def clear_all
  @store.clear
  self
end

#load(thread_id) ⇒ Object?

Returns state object or nil.

Parameters:

  • thread_id (String)

Returns:

  • (Object, nil)

    state object or nil



22
23
24
# File 'lib/phronomy/state_store/in_memory.rb', line 22

def load(thread_id)
  @store[thread_id]
end

#save(state) ⇒ self

Parameters:

  • state (Object)

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

Returns:

  • (self)


15
16
17
18
# File 'lib/phronomy/state_store/in_memory.rb', line 15

def save(state)
  @store[state.thread_id] = state
  self
end