class Asynchronic::DataStore::InMemory

Attributes

hash[R]
keys_mutex[R]
mutex[R]

Public Class Methods

connect(object_id) click to toggle source
# File lib/asynchronic/data_store/in_memory.rb, line 7
def self.connect(object_id)
  connections[object_id]
end
connections() click to toggle source
# File lib/asynchronic/data_store/in_memory.rb, line 11
def self.connections
  @connections ||= {}
end
new() click to toggle source
# File lib/asynchronic/data_store/in_memory.rb, line 15
def initialize
  @hash = {}
  @mutex = Mutex.new
  @keys_mutex = Hash.new { |h,k| h[k] = Mutex.new }
  self.class.connections[object_id] = self
end

Public Instance Methods

[](key) click to toggle source
# File lib/asynchronic/data_store/in_memory.rb, line 22
def [](key)
  Marshal.load(hash[key.to_s]) if hash.key? key.to_s
end
[]=(key, value) click to toggle source
# File lib/asynchronic/data_store/in_memory.rb, line 26
def []=(key, value)
  mutex.synchronize { hash[key.to_s] = Marshal.dump(value) }
end
connection_args() click to toggle source
# File lib/asynchronic/data_store/in_memory.rb, line 47
def connection_args
  [object_id]
end
delete(key) click to toggle source
# File lib/asynchronic/data_store/in_memory.rb, line 30
def delete(key)
  hash.delete key.to_s
end
delete_cascade(key) click to toggle source
# File lib/asynchronic/data_store/in_memory.rb, line 34
def delete_cascade(key)
  keys.select { |k| k.sections.first == key }
      .each { |k| delete k }
end
keys() click to toggle source
# File lib/asynchronic/data_store/in_memory.rb, line 39
def keys
  hash.keys.map { |k| Key[k] }
end
synchronize(key, &block) click to toggle source
# File lib/asynchronic/data_store/in_memory.rb, line 43
def synchronize(key, &block)
  keys_mutex[key].synchronize(&block)
end