An ActiveSupport cache store that uses the C-based libmemcached client through Evan Weaver's Ruby/SWIG wrapper, memcached. libmemcached is fast (fastest memcache client for Ruby), lightweight, and supports consistent hashing, non-blocking IO, and graceful server failover.

This cache is designed for Rails 3+ applications.


You'll need the memcached gem installed:

gem install memcached

or in your Gemfile

gem 'memcached'

There are no other dependencies.


Just add to your Gemfile

gem 'rails3_libmemcached_store'

and you're set.


This is a drop-in replacement for the memcache store that ships with Rails. To enable, set the config.cache_store option to libmemcached_store in the config for your environment

config.cache_store = :libmemcached_store

If no servers are specified, localhost is assumed. You can specify a list of server addresses, either as hostnames or IP addresses, with or without a port designation. If no port is given, 11211 is assumed:

config.cache_store = :libmemcached_store, %w(cache-01 cache-02

Standard Rails cache store options can be used

config.cache_store = :libmemcached_store, '', {:compress => true, :expires_in => 3600}

More advanced options can be passed directly to the client

config.cache_store = :libmemcached_store, '', {:client => { :binary_protocol => true, :no_block => true }}

You can also use :libmemcached_store to store your application sessions

require 'action_dispatch/session/libmemcached_store'
config.session_store = :libmemcached_store, :namespace => '_session', :expire_after => 1800


Used with Rails, libmemcached_store is at least 1.5x faster than dalli. See BENCHMARKS for details


Thanks to Brian Aker ( for creating libmemcached, and Evan Weaver ( for the Ruby wrapper.