2

I read a few tutorials on getting memcached set up with Rails (2.3.5), and I'm a bit lost.

Here's what I need to cache: I have user-specific settings that are stored in the db. The settings are queried in the ApplicationController meaning that a query is running per-request.

I understand that Rails has built-in support for SQL cacheing, however the cacheing only lasts for the duration of an Action.

I want an easy way to persist the settings (which are also ActiveRecord models) for an arbitrary amount of time. Bonus points if I can also easily reset the cache anytime a setting changes.

thanks

user94154
  • 16,176
  • 20
  • 77
  • 116

2 Answers2

5

Gregg Pollack of RailsEnvy did a series of "Scaling Rails" screencasts a while back, which are now free (thanks to sponsorship by NewRelic). You might want to start with episode 1, but episode 8 covers memcached specifically:

http://railslab.newrelic.com/2009/02/19/episode-8-memcached

1

Sounds like what you want is an object cache between the DB and ActiveRecord. The only decent one we've found so far is Identity Cache (https://github.com/Shopify/identity_cache). It's brand new so it's a bit rough around the edges, but gets the job done for basic caching.

hurshagrawal
  • 663
  • 6
  • 15