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.

3 comments:

Aaron said...

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

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.

bourne111 said...

MBT shoes|MBT shoes
supra shoes|supra shoes
Nike shoes|nike shoes
adidas sneakers|adidas sneakers
adidas outlet|adidas outlet
Nike outlet|nike outlet
Nike sneakers|nike sneakers

basketball shoes,nike basketball shoes
Nike Outlet,adidas outlet
nike shoes|nike shoes
adidas shoes|adidas shoes
basketball shoes|basketball shoes
NBA basketball shoes|NBA basketball shoes
Nike Basketball shoes|Nike Basketball shoes
adidas basketball shoes|adidas basketball shoes

LeBron James Shoes|LeBron James Shoes
Kobe Bryant Shoes|Kobe Bryant Shoes
LeBron James Shoes|LeBron James Shoes
Kobe Bryant Shoes|Kobe Bryant Shoes

nike shoes,adidas shoes,nike outlet,adidas outlet,basketball shoes,nike basketball shoes,adidas basketball shoes,nba basketball shoes