memcache-client

Rubyforge Project:

rubyforge.org/projects/rctools/

About

memcache-client is a fast memcached client.

Installing memcache-client

Just install the gem

$ sudo gem install memcache-client

Using memcache-client

CACHE = MemCache.new :c_threshold => 10_000,
                     :compression => true,
                     :debug => false,
                     :namespace => 'my_namespace',
                     :readonly => false,
                     :urlencode => false
CACHE.servers = 'localhost:11211'

You can specify multiple servers by sending an Array of servers to #servers=.

Using memcache-client with Rails

Rails will automatically load the memcache-client gem, but you may wish to uninstall Ruby-memcache, I don’t know which one it will pick by default.

Add your environment-specific caches to config/environment/*. If you run both development and production on the same machine be sure to use different namespaces. Be careful when running tests under memcache, you may get strange results, it will be less of a headache to simply use a readonly memcache when testing.

memcache-client also comes with a wrapper called Cache in memcache_util.rb for use with Rails. To use it be sure to assign your memcache connection to CACHE. Cache returns nil on all memcache errors so you don’t have to rescue yourself. It has #get, #put and #delete module functions.