O'Reilly logo

Heroku Cookbook by Mike Coutermarsh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Caching rendered views

Rendering a page in Rails isn't a simple process. It usually consists of several database queries that render various partials and convert HAML to HTML. Repeating this entire process for each page load is wasteful. In this recipe, you will learn how to cache your views so that you only have to render them once. You'll also learn how to use key-based cache expiration to ensure that you're always serving the latest content.

How to do it…

In this recipe, we'll use the Blogger application as an example to implement view caching. This time, we will optimize posts#show using caching to make viewing a post as fast as possible.

Note

Make sure that caching is enabled in config/environments/development.rb and config.action_controller.perform_caching ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required