Posts Tagged ‘rails’

Rails MemCacheStore Fu

Wednesday, June 10th, 2009

Or 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.

  1. get Mike Perham’s latest memcache-client on github or simply:
    sudo gem install memcache-client

    make sure to remove any other memcache-client gems from your system.

  2. follow Mike’s instructions to performs brain surgery on the Ruby environment to override ActiveSupport memcache-client
  3. to control the MemCacheStore initialization using the options in your memcached.yml file, grab my memcached-config code from github
  4. 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.