Cache Streamed Data

I'm writing an app that does a lot of data visualization using
RMagick. Most of the pages in my app are pretty basic with a few
textual descriptions of the data and then a bunch of img tags linking
to other actions that render the graphs and use send_data to send the
images to the client.

Most of the data we work with gets uploaded via an import script each
night so the pages and graphs are basically static throughout the day
when all of our users are hitting the page. I'd like to cache the
generated images server side and then use standard rails sweepers to
invalidate it when the import script (which uses all our standard
models) runs.

It seems that caches_action and caches_page do not work when no view
is actually rendered (i.e. send_data is used to send the response.)
I've done a fair amount of Googling and haven't found anything about
this yet, but I thought it would be worth a post here to see if anyone
knew of a clean easy way to do this.

Thanks in advance,
Mike

You know, it probably wouldn’t be that difficult to do this yourself. Instead of calling send_data directly, make some helper called “render_graph” which does something like

if cached_file_exists
send_data “cached_file”
else
generate_chart # generate chart and render to cache
end

I’m trying to implement this right now with some PDFs I’m generating on the fly. In my case I know the name of the file, so it’s basically serve it, and if you don’t find it, generate it.

I know that doesn’t help much, but I know of no existing solutions to this problem.

I think you're right. I'm going to just bite the bullet and write my
own. Maybe I'll even turn it into a plugin...

Thanks for the response.