Action Cache Issue Rails

August 30, 2007

Ran into an interesting caching issue today which has been hiding in my web application oentries for quite some time. It all comes down to the locations that you serve your application from.

Previously (up to 10 minutes ago) I would serve it from both www.oentries.com and oentries.com. Recently I have been noticing a weird behaviour of the cached entry lists not getting updated. I have started using oentries.com for this recently. I then checked the equivalent URL on www.oentries.com and all was well.

Essentially, when the expire_action call is made, it uses something similar to url_for which generates the url from the headers to expire. Since all the users use www.oentries.com this cache is cleared out all the time when people enter for orienteering events, and since nobody is using oentries.com this isn’t getting cleared out.

The solution was to change the nginx config to put a global url rewrite to force www on urls. So now oentries.com gets redirected to www.oentries.com

I could have also improved the cache expiry code to expire the cache for both domains but as this is also an issue for SEO when you are serving the same app of different domains I decided that the URL rewrite was both a quicker fix (thanks to the nginx config generator now with SSL support thanks to me) and the right thing to do.