This post is part of a series of 31 Rails 4 articles being released each day in December 2012.
After maintaining the memcache-client gem for over two years, Mike Perham wrote Dalli. Dalli is a high performance drop-in replacement for memcache-client, and has been the client of choice for the last two years.
Some benefits of using Dalli are:
- It is approximately 20% faster than the memcache-client gem.
- Dalli has the ability to handle failover with recovery and adjustable timeouts.
- The codebase is threadsafe.
- It uses the newer memcached binary protocol.
As of Rails 4, Dalli is the new
mem_cache_store. You will not have to change any code in your environment configuration files when upgrading:
# config/environments/production.rb config.action_controller.perform_caching = true config.cache_store = :mem_cache_store
To get up and running with Dalli, just add it to your
# Gemfile gem 'dalli'
Attempting to run a Rails application configured to use
mem_cache_store without first including the
dalli gem in your
Gemfile, will result in the following error:
You don't have dalli installed in your application.
Please add it to your Gemfile and run bundle install
Dalli is dependent on memcached 1.4+. If you are running anything older than memcached version 1.4 on your servers, an upgrade will be required before you can use Rails 4.
You can take advantage of everything Dalli has to offer in your Rails 3 applications today. Just add
dalli to your
Gemfile and set
dalli_store as the
# config/environments/production.rb config.cache_store = :dalli_store