Rails MemCacheStore Fu
Wednesday, June 10th, 2009Or how to use the latest memcache-client (1.7.4 as of this writing) over the vendored copy in Rails and control the MemCacheStore initialization using the cache_fu/act_as_cached memcached.yml config file.
- get Mike Perham’s latest memcache-client on github or simply:
sudo gem install memcache-clientmake sure to remove any other memcache-client gems from your system.
- follow Mike’s instructions to performs brain surgery on the Ruby environment to override ActiveSupport memcache-client
- to control the MemCacheStore initialization using the options in your memcached.yml file, grab my memcached-config code from github
- include the following code in your environments/*.rb files:
unless (memcached_config = MemcachedConfig.new).disabled? memcached_options = memcached_config.options config.cache_store = :mem_cache_store, memcached_options.delete(:servers), memcached_options end
By using MemcachedConfig this way, all the recognized options by memcache-client in your memcached.yml config file, such as :namespace, will be used. You can also add specific memcache-client options such as :failover or :timeout in you memcached.yml.
