Class: Cubism::CubicleStore

Inherits:
Object
  • Object
show all
Defined in:
lib/cubism/cubicle_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ CubicleStore

Returns a new instance of CubicleStore.



5
6
7
# File 'lib/cubism/cubicle_store.rb', line 5

def initialize(key)
  @blocks = Kredis.hash key
end

Instance Method Details

#[](key) ⇒ Object



9
10
11
# File 'lib/cubism/cubicle_store.rb', line 9

def [](key)
  Marshal.load(@blocks[key]) if @blocks[key]
end

#[]=(key, value) ⇒ Object



13
14
15
16
17
# File 'lib/cubism/cubicle_store.rb', line 13

def []=(key, value)
  mutex.synchronize do
    @blocks[key] = Marshal.dump value
  end
end

#clearObject



28
29
30
31
32
33
# File 'lib/cubism/cubicle_store.rb', line 28

def clear
  mutex.synchronize do
    # kredis #remove
    @blocks.remove
  end
end

#fetch(key, value = nil, &block) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/cubism/cubicle_store.rb', line 19

def fetch(key, value = nil, &block)
  if self[key].nil?
    yield value if block
    self[key] = value
  end

  self[key]
end

#sizeObject



35
36
37
# File 'lib/cubism/cubicle_store.rb', line 35

def size
  @blocks.to_h.size
end