lib/fastcache/bucket/modulus.rb in binary42-fastcache-0.1 vs lib/fastcache/bucket/modulus.rb in binary42-fastcache-0.2

- old
+ new

@@ -1,17 +1,15 @@ class FastCache::ModulusBucket - def initialize(key, hash) - @digest = hash.new(key).hexdigest.to_i(16) - @key = key + def initialize(nodes) + @nodes = nodes end - def select(nodes) - count = nodes.size - # Note: An upper bound on tries ought to be given at some point + def select(hash) + count = @nodes.size count.times do |i| begin - break yield(@key, nodes[(@digest + i) % count]) + break yield(@nodes[(hash + i) % count]) rescue FastCache::Memcache::ProtocolError next end raise 'Unable to find suitable node to communicate with' end