Rails Caching: A problem with etags and a solution
A few months ago I blogged about a problem I was having with busting the http caching Rails does. That post had a pretty naive solution, and I wanted to provide an update to raise a bit more awareness of the problem and a better solution.
First, I’m a bit surprised that this isn’t a problem folks are talking more about.
The basic gist of the problem is: when you use Rails http caching using something like fresh_when in your controllers, simply deploying your application will break the styling of your application for anyone who has one of your pages already http cached. Let me show you what I mean with a super simple application.
All this application does is render a simple view, and makes sure to set an etag.
class WelcomeController < ApplicationController
def index
fresh_when(etag: "VERSION_1")
end
end
In your app the fresh_when likely wraps around an object and uses...