Class: FastCache::ModulusBucket
- Inherits:
-
Object
- Object
- FastCache::ModulusBucket
- Defined in:
- lib/fastcache/bucket/modulus.rb
Instance Method Summary collapse
-
#initialize(key, hash) ⇒ ModulusBucket
constructor
A new instance of ModulusBucket.
- #select(nodes) ⇒ Object
Constructor Details
#initialize(key, hash) ⇒ ModulusBucket
Returns a new instance of ModulusBucket.
3 4 5 6 |
# File 'lib/fastcache/bucket/modulus.rb', line 3 def initialize(key, hash) @digest = hash.new(key).hexdigest.to_i(16) @key = key end |
Instance Method Details
#select(nodes) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/fastcache/bucket/modulus.rb', line 8 def select(nodes) count = nodes.size # Note: An upper bound on tries ought to be given at some point count.times do |i| begin break yield(@key, nodes[(@digest + i) % count]) rescue FastCache::Memcache::ProtocolError next end raise 'Unable to find suitable node to communicate with' end end |