Class: Teams::Storage::MemoryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/teams/storage/memory_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(initial = {}) ⇒ MemoryStore

Returns a new instance of MemoryStore.



6
7
8
9
10
11
12
# File 'lib/teams/storage/memory_store.rb', line 6

def initialize(initial = {})
  @data = initial.dup
  # The store is shared across request threads in multi-threaded Rack
  # servers. The upstream SDKs run single-threaded event loops and can
  # skip locking; Ruby cannot.
  @mutex = Mutex.new
end

Instance Method Details

#delete(key) ⇒ Object



22
23
24
# File 'lib/teams/storage/memory_store.rb', line 22

def delete(key)
  @mutex.synchronize { @data.delete(key) }
end

#get(key) ⇒ Object



14
15
16
# File 'lib/teams/storage/memory_store.rb', line 14

def get(key)
  @mutex.synchronize { @data[key] }
end

#set(key, value) ⇒ Object



18
19
20
# File 'lib/teams/storage/memory_store.rb', line 18

def set(key, value)
  @mutex.synchronize { @data[key] = value }
end