Class: TieredCaching::ReplicatingStore

Inherits:
Object
  • Object
show all
Defined in:
lib/tiered_caching/replicating_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(internal_stores, replication_factor = nil) ⇒ ReplicatingStore

Returns a new instance of ReplicatingStore.



3
4
5
6
# File 'lib/tiered_caching/replicating_store.rb', line 3

def initialize(internal_stores, replication_factor = nil)
  @internal_stores = internal_stores
  @replication_factor = replication_factor || internal_stores.count
end

Instance Method Details

#clearObject



31
32
33
# File 'lib/tiered_caching/replicating_store.rb', line 31

def clear
  @internal_stores.map(&:clear)
end

#delete(key) ⇒ Object



25
26
27
28
29
# File 'lib/tiered_caching/replicating_store.rb', line 25

def delete(key)
  replication_range(key).map do |index|
    @internal_stores[store_index(index)].delete(key)
  end
end

#get(key) ⇒ Object



15
16
17
18
19
# File 'lib/tiered_caching/replicating_store.rb', line 15

def get(key)
  index = store_index(hash_for_key(key))
  end_index = store_index(hash_for_key(key) + @replication_factor)
  recursive_get(key, end_index, index)
end

#getset(key) ⇒ Object



21
22
23
# File 'lib/tiered_caching/replicating_store.rb', line 21

def getset(key)
  get(key) || set(key, yield)
end

#set(key, value) ⇒ Object



8
9
10
11
12
13
# File 'lib/tiered_caching/replicating_store.rb', line 8

def set(key, value)
  replication_range(key).map do |index|
    @internal_stores[store_index(index)].set(key, value)
  end
  value
end