Using memcache client with ruby
Ok, for me, the problem was the security groups. You can only access Elasticache nodes from ec2 instances that have a security group that is listed in the Elasticache security group.
So for me, my ec2 instance has a security group of "web". In elasticache, I then added "web" to the "default" elasticache security group.
Further explanation here: http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/CacheSecurityGroup.html
Also, try using either of these two gems:
https://github.com/mperham/dalli
https://github.com/ktheory/dalli-elasticache
I'm using the latter and it works great because it uses autodiscovery of the nodes.
Memcached / Dalli couldn't fetch data from other servers
I had quick look at Daili code base. It uses consistent hashing for distributing keys to servers.
https://github.com/mperham/dalli/blob/master/lib%2Fdalli%2Fring.rb#L10
entry_count_for(server, servers.size, total_weight).times do |idx|
hash = Digest::SHA1.hexdigest("#{server.name}:#{idx}")
value = Integer("0x#{hash[0..7]}")
continuum << Dalli::Ring::Entry.new(value, server)
end
and
def entry_count_for(server, total_servers, total_weight)
((total_servers * POINTS_PER_SERVER * server.weight) / Float(total_weight)).floor
end
The keyspace of each server depends on total servers, weight and server name. So that the keyspace will be different with different total servers or server name. I think that explanation fits your problem.
Group data by Namespace in memcache
As per response received from dalli gem github tracker it is not possible to group by namespace.
Can't read key from memcached using dalli
The default Dalli timeout is 500ms. Given that memcache response times are typically single digit milliseconds, and that you put your memcache instances close to your servers this is usually ample.
On the other hand given that you are connecting via an ssh tunnel you might see much greater latencies you might want to increase the timeout:
Dalli::Client.new("127.0.0.1:10001", socket_timeout: 2.0)
How to use Memcache and Ruby On Rails default memory store at the same time?
Rails.cache
is just a cache store that is created for your convenience. There's nothing stopping you doing something like
::MEMORY_STORE = ActiveSupport::Cache::MemoryStore.new
and then when you want to use that store instead of Rails.cache
you would do
MEMORY_STORE.fetch('some_key') {}
Although, as @leonardoborges commented, I'm not sure why you would want to do this
Related Topics
How to Invoke an Instance Method on a Ruby Module Without Including It
Rvm Is Not a Function, Selecting Rubies with 'Rvm Use ...' Will Not Work
How to Know What Is Not Thread-Safe in Ruby
Where to Define Custom Error Types in Ruby And/Or Rails
How to Run a Single Test in Minitest
Welcome/Home Page in Ruby on Rails - Best Practice
Ubuntu Rails Install Fails on Zlib
How to Install Rvm System Requirements Without Giving Sudo Access for Rvm User
How to Test a File Upload in Rails
File Upload with Activeadmin Rails Using Paperclip
How to Sort an Array of Hashes by a Value in the Hash
Can Someone Explain the Class.Superclass.Class.Superclass Paradox
How to Check If a Given Directory Exists in Ruby
Differencebetween Send_Data and Send_File in Ruby on Rails
How to Have Multiple Versions of Ruby and Rails, and Their Combinations on Windows
Differencebetween Class and Klass in Ruby
Ruby on Rails Plural (Controller) and Singular (Model) Convention - Explanation