Follow Along as I Stumble on the Path to Learning RoR

Caching Rails 3 on Heroku

To learn about caching, I used a few different resources.

The three basic types of caching are:

  • page caching – mainly for static pages, it will not work if any filters are applied to the controller of the page (ie authorizations)
  • action caching – typically what you’d used to cache a page if they have filters
  • fragment caching – allows for caching of blocks of html on a page (if you can’t cache the whole page) or for partials

Since I’m on Heroku, the first place to learn was Heroku’s documentation.  It’s important to read the Heroku docs first because some standard Rails functions work differently on Heroku’ platform.  Mainly, for page caching (uses different syntax than standard rails) and action caching (mostly dependent on memcache, so you need to set your app up accordingly).

Overview of caching on Heroku
http://devcenter.heroku.com/articles/caching-strategies

http://devcenter.heroku.com/articles/building-a-rails-3-application-with-the-memcache-addon

There’s also a Rails Guide on Caching (just remember to ignore page caching part):
http://guides.rubyonrails.org/caching_with_rails.html

However, the most extensive (and useful) one for me was from Adam Hawkins at (especially for fragment caching):
http://broadcastingadam.com/2011/05/advanced_caching_in_rails

I also needed to learn about sweepers, in order to observe for changes that would impact another controller’s pages.  This Stack Overflow post helped me learn to put the sweeper in with the models and to ensure that I updated the correct controller:
http://stackoverflow.com/questions/2247410/action-caching-is-not-expiring-correctly-even-when-i-can-see-its-being-called

Advertisements

Comments are closed.