Friday, July 24, 2009

Conditionally using memcached in Rails development mode

Problem: sometimes you want Rails to use the MemCacheStore in development mode, but only when memcached is running. Otherwise you want to fall back to the regular memory store.

Solution: Drop this gist into your development.rb file. It checks to see if memcached is running on the default port on localhost and sets config.cache_store appropriately.

With this code in place, not everyone on your team has to be running memcached, and you only have to run it when you're testing something that involves memcached.

This saved me some aggravation and I hope it helps you too.

Labels:

2 Comments:

At July 25, 2009 12:11 AM , Blogger Aaron said...

That's cool, but do you really want to output to stderr ?

 
At July 25, 2009 9:10 AM , Blogger Mike Subelsky said...

I'd rather log it, but at that point in time no loggers are available (plus as you know in OIB we do weird stuff with the loggers anyway) -- also, since this is just for dev mode, I figure you want to get immediate visual feedback about caching.

 

Post a Comment

Links to this post:

Create a Link

<< Home