Book Image

Heroku Cookbook

By : Mike Coutermarsh
Book Image

Heroku Cookbook

By: Mike Coutermarsh

Overview of this book

Heroku is a Platform as a Service that enables developers to rapidly deploy and scale their web applications. Heroku is designed for developer happiness, freeing developers from doing system administrative tasks such as configuring servers and setting up load balancers. Developers are able to focus on what they do best, building web applications, while leaving the details of deployment and scaling to the experts at Heroku. This practical guide is packed with step-by-step solutions to problems faced by every production-level web application hosted on Heroku. You'll quickly get comfortable with managing your Heroku applications from the command line and then learn everything you need to know to deploy and administer production-level web applications.
Table of Contents (17 chapters)
Heroku Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 is set to true.

  1. Currently, if we try to view a post, our application does the following to render the page:

    Started GET "/posts/2" for 127.0.0.1 at 2014-08-09 14:29:06 -0400
    Processing by PostsController#show as HTML
      Parameters: {"id...