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

Implementing low-level caching in Rails


We can significantly increase the performance of our application by caching queries to our database. In Rails, this is known as low-level caching. In this recipe, you will learn how to use Rails.cache.fetch to cache database queries. You'll see that this technique can be used to cache any expensive operations. Any outside API or network calls also make great candidates for low-level caching. We will be able to use this technique to make significant performance improvements to our application. We'll reduce the load on our database as well as speed up our overall response times.

Getting ready

To complete this recipe, our Rails application needs to have either Redis or memcached set up. For us to test cache in development, we will also need to have it enabled in our development config.

Let's open up config/environments/development.rb now and ensure that we have the following line set to true:

  config.action_controller.perform_caching = true

How to do it…

Let...