Page and Action Caching Gem Extraction [Rails 4 Countdown to 2013]

Posted on

This post is part of a series of 31 Rails 4 articles being released each day in December 2012.

As of Rails 4, page and action caching has been removed from the framework. While they are no longer available out of the box, each feature has been extracted to a gem. Both page and action caching can be restored in Rails 4 applications by including the actionpack-page_caching and actionpack-action_caching gems in your Gemfile respectively.

Rationale for Removal

The biggest issue with page and action caching is the requirement of having to manually expire caches. Your application soon becomes littered with cache sweepers and observers that are solely responsible for cache expiration. With Rails 4 advocating "Russian Doll Caching" as the strategy to use moving forward, page and action caching no longer has a purpose within the framework.

Upgrade Path

Personally, I would advice against using a strategy such as page and/or action caching in your Rails applications today. Page caching limits your capability to scale horizontally, as you would have to manually remove expired files from each server your application is deployed to.

Sometimes people create static sites using Rails and want to page cache everything. If your application is completely stateless and you want the benefit of just serving files from a single web server, using something like middleman is a great alternative. Middleman is a static site generator providing many integrations Rails developers are familiar with, such as Sass, CoffeeScript, and Haml.

A great high performance solution to caching stateless responses is a reverse-proxy cache, such as Varnish with HTTP cache headers.


This post is by Kevin Faustino. Kevin is the Chief Craftsman of Remarkable Labs and also the founder of the Toronto Ruby Brigade.


comments powered by Disqus