Class: TieredCaching::ReplicatingStore
- Inherits:
-
Object
- Object
- TieredCaching::ReplicatingStore
- Defined in:
- lib/tiered_caching/replicating_store.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #get(key) ⇒ Object
- #getset(key) ⇒ Object
-
#initialize(internal_stores, replication_factor = nil) ⇒ ReplicatingStore
constructor
A new instance of ReplicatingStore.
- #set(key, value) ⇒ Object
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
#clear ⇒ Object
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 |