Output caching refers to storing the output of Rails’ views so that the next request requires less overhead to recreate. Rails provides output caching at three levels of granularity, each useful for different purposes:
Writes the complete response body to a static file in the public directory, so that subsequent requests are served directly by the web server
Caches the complete response body, but still processes each request through Rails
Stores subpage level snippets of output
Not everything is a candidate for caching—highly dynamic applications that deal with ever-changing data may not benefit much or at all. But many pages will get a dramatic speedup from caching, especially high-traffic pages that summarize a large amount of data and don’t need up-to-the-second freshness.
By default, output caching isn’t performed in the development environment. To enable it for debugging, edit config/environments/development.rb and enable caching with this setting:
config.action_controller.perform_caching = true
The first type of output caching, and the bluntest, is page caching. Page caches store the output of an entire action at once, and subsequent requests to the page bypass filters—in fact, they bypass Rails entirely.
Page caching relies on how the web server in front of Rails (such as Apache or lighttpd) is configured. Typically, when the web server receives a request for a URL in a Rails application, it will first check ...