Page caching and content types for feeds

Page caching inside Rails is great for HTML, but it will only send the text/html content type. Here’s a quick recipe for caching other types of content.

This isn’t beautiful, or particularly elegant, but if you only need to cache a few rss feeds, it’s amazingly easy. Inside your apache virtual host configuration, simply add:

  <Location /item/rss>
    ForceType application/rss+xml

The argument in the Location tag should be the full path to your cached item (without the html). You can set any content type. This gives you all of the benefits of page caching while still sending the correct content type.