Just thought I’d post some details of an interesting little quirk I’ve
with page caching.
For a site I’ve just built for a small music festival, there are a
artist profiles. I’m storing the artists in my database, but using
caches_page to speed things up when displaying the details to the
I’ve also made it so that instead of the numerical ID appearing in the
uses the artist’s name instead. So if someone called “Bob S.” was
playing, the URL would be: /artists/Bob+Smith
Now, with the page caching, it works fine for most of the artists, since
Smith’s cached page gets stored in myapp/public/artists/Bob+Smith.html
But what if “B. Smith” was playing - you’d expect it to generate
“B.+Smith.html”, but it doesn’t, just a file called “B.+Smith” with no
on the end of it. It seems the caching system does not add a file
to a page name that already has a dot (period) in it.
The end result of this is that Apache (this is on Dreamhost, btw) fails
recognise that the cached page is HTML (since it has no extension) and
the raw HTML as text/plain… not pretty!
Furthermore, you won’t notice this on the first page view, since at the
it generates the cached page using Rails, I guess it’s serving up the
from the Rails controller, rather than the newly generated cached page.
This problem only becomes apparent on the second page view - and only
if you do a shift-reload forced refresh from the server to bypass your
I quickly tried renaming the problematic cache files and putting “.html”
the end of their names just to see if that helped, but then we’re back
square one - the cache thinks it’s the first time that page has been
so a new file without a “.html” gets created (and works first time), and
you’re back to the raw HTML being served up as plain text on subsequent
So, the workaround for this is to (assuming all the pages that are being
cached should be served as text/html) make a .htaccess file with the
following line in it, and put it in the same directory as the
That solves the problem and serves all the pages (even those without
extensions) as text/html - though whether this is a bigger issue (maybe
a slight bug) with caches_page, I guess is up for debate.
Anyway, I thought I’d post my easy workaround in case anyone else finds
themselves in the same situation. (Though surely I’m not the first one
Rent-A-Monkey Website Development