Jemery Kemper recently upgraded Rails 2.3′s vendored copy of memcache-client to the 1.6.4 release. But what do you do if you are running Rails 2.1/2.2 and want to take advantage of the massive speedup in 1.6.x? You write some really ugly code that performs brain surgery on the Ruby environment to override ActiveSupport. Create config/initializers/memcache-client-upgrade.rb with this code:
require 'rubygems' # Brain surgery to use our own version of memcache-client without # having to modify activesupport directly. # Unload any previous instance of the class if Object.const_defined? :MemCache Object.instance_eval { remove_const :MemCache } end # Pull in the exact version we want gem 'memcache-client', '1.6.5' # Ensure that the memcache-client path is at the front of the loadpath $LOAD_PATH.each do |path| if path =~ /memcache-client/ $LOAD_PATH.delete(path) $LOAD_PATH.unshift(path) end end # If Ruby thinks it's already loaded memcache.rb, force # a reload otherwise just require. if $".find { |file| file =~ /\Amemcache.rb\Z/ } load 'memcache.rb' else require 'memcache' end
If someone knows of a cleaner way to do this, please let me know.
Thanks.
It’s cleaner if you move it to config/initializers/memcache_fix.rb
Thanks, good idea. I forgot that load order doesn’t matter since we’re unloading everything. I’ve updated the post.
Wait! I think it does matter. It won’t work from initializers scripts! But why ?
Yikes, that sucks. Hopefully they will add the 1.7.x to rails so we don’t have to do this
Pingback: eventually consistent » Blog Archive » Rails MemCacheStore Fu
Thanks, that worked for me with memcache-client 1.7.4 and Rails 2.2.2.
I have also written a quick tutorial on how to do this and also control the MemCacheStore options using a memcached.yml config file (from cache_fu/acts_as_cached) on http://eventuallyconsistent.com/blog/2009/06/rails-memcachestore-fu/
Colin.
Does this work if memcache-client 1.7.4 is vendored?
I am getting this error:
Could not find RubyGem memcache-client (= 1.7.4)
On this line:
# Pull in the exact version we want
gem ‘memcache-client’, ’1.7.4′
Any tips?
I guess not.
Pingback: FoundChris » Blog Archive » Using the latest memcache-client in Rails
Here is how I got 1.7.4 going without relying on an external gem:
http://www.foundchris.com/2009/07/02/using-the-latest-memcache-client-in-rails/
Cheers.
Here’s how I’m using the vendored gem in Rails 2.2.x:
http://gist.github.com/156741
Pingback: Ruby Memcache Client using Unix Sockets « Blog | Confiz Solutions