Caching and mongrel


I have turned on caching and am using the action controller directive
caches_page for an action that returns an image file (used in the HTML
img src attribute). The first time I visit the page which contains
those img tags, all looks great and a bunch of pages are created in
the location where the cache is being stored (defaults to RAILS_ROOT +
“/public”). However, on the second visit, the page is missing some
images and when looking at the files in the cache directory, I notice
that the images which displayed correctly on the second visit contain
simply a binary image file. However, the files that did not work
contain some text like:


Does anyone know what is going on there? Is this a mongrel cache

I found out what was going on and thought you should know. The action
which was being cached used the send_file action controller method.
However, (this was a pain to diagnose) when using default options
the :stream => true option will cause the data to be generated AFTER
the cache copy is taken hence the stuff in the cache is actually the
instruction to stream the file. So, the fix is to say :stream =>
false in the send_file method and VOILA! I guess that’s why I was the
only poor soul seeing this cause probably no one caches requests
generated by send_file.