BigTablet.com Blog

May 18, 2009

Rails 2.3 and Memcache Server Hashes

Filed under: Ruby & Rails — Tags: — ciddennis @ 3:39 pm

So at another project I have situation where I have to share some information in memcache with a java client.   We use a cluster of about 5 memcachd servers to do this data sharing.    This has worked fine for a number of months but when I recently upgraded to rails 2.3 I found it would no longer find right servers.   When I looked in to it more I found that the memcache_client library changed its servers selection algorithm to use something called consistent hashing.  Anyway now the default Rails.cache.fetch does not work.  So while I look for a java client that uses the same server selection algorithm I just did this:


def get_memcach_token(mem_cache_id)
Rails.cache.addresses.each { |address|
value = MemCache.new([address]).get(mem_cache_id,{:raw => true})
return value if value
}
nil
end

The other option is to go back to memcache_client 1.5.  But then you are going to be stuck there forever.

Create a free website or blog at WordPress.com.