RubyFlow The Ruby and Rails community linklog

How to bust your Rails etag cache on deployment.

A simple tip to handle etag busting on deploying your Rails app.

Comments

This works fine provided you only have a single instance of your app running, otherwise that timestamp may be different for each instance, causing the etags to change depending on which instance is serving each request - therefore defeating the whole point of them.

If you want to handle this properly, you’ll want to use something like the current Git checkout hash, or a timestamp persisted in a file (I believe Capistrano does this) - then the ENV[“RAILS_APP_VERSION”] variable is more suitable (purely semantics). I’m not sure either of those methods are available for Heroku though…

I’ve just confirmed Capistrano does indeed do this… it prints a revision hash into a file, see:

(echo 603cee4906d2f7c43b6911e3ba2534cc82593d14 > /path/to/app/releases/20120730094816/REVISION)

This command will be the same, executed across all servers so it’s safe to use in your initializer.

So here’s what I’d do:

revision_file = Rails.root.join("REVISION") if File.exist?(revision_file) ENV["RAILS_APP_VERSION"] = File.read(revision_file) end

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in