Read my latest article: 8 things I look for in a Ruby on Rails app (posted Thu, 06 Jul 2017 17:59:00 GMT)

Setting Akamai Edge-Control headers with Ruby on Rails

Posted by Tue, 19 Jun 2012 05:54:00 GMT

Just a short and sweet little tip.

Several months ago we moved one of our clients over to Akamai’s Content Delivery Network (CDN). Ww were previously using a combination of Amazon S3 and CloudFront with some benefits, but we were finding several key areas of the world were not s covered by Amazon (yet) for asset delivery. Along with that, we really wanted to take advantage of the CDN for more of our HTML content with a lot of complex rules that related to geo-targeting and regionalization of content.

I’ll try to cover those topics in another post, but wanted to share a few tidbits of code that we are using to manage Akamai’s Edge-control caches from within our Rails application.

With Akamai, we’re able to tell their Edge servers whether it should hold on to the response so it can try to avoid an extra request to the origin (aka our Rails application). From Rails, we just added a few helper methods to our controllers so that we can litter our application with various expiration times.

  # Sets the headers for Akamai
  # acceptable formats include:
  #   1m, 10m, 90m, 2h, 5d
  def set_cache_control_for(maxage="20m")
    headers['Edge-control'] = "!no-store, max-age=#{maxage}"

This allows us to do things like:

  class ProductsController < ApplicationController
    def show
      @product = Product.find(params[:id])

Then when Akamai gets a request for, it’ll try to keep a cached copy around for four hours before it hits our server again.

Rails applciation caching with memcache

Posted by Sat, 14 Oct 2006 23:24:00 GMT

Courtenay has posted a step by step tutorial on using memcache within your Rails application. He not only discusses caching… but also how to “precache the data so that each page load is blazing fast without sacrificing user experience.

Read more about it on the blog.

< court3nay> robbyonrails: hey, i wrote that line just for you
< court3nay> robbyonrails: the one you quoted. i was actually thinking, "hmm, i bet robby will like this quote" 

I’m touched… and it’s great to hear that people are thinking more about these problems. :-)