# Cache Streamed Data

**URL:** <https://www.ruby-forum.com/t/cache-streamed-data/141829>\
**Category:** Rails\
**Created:** [June 30, 2008, 9:59pm UTC](https://www.ruby-forum.com/t/cache-streamed-data/141829 "2008-06-30T21:59:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Deck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc8723/32.png) [@Mike\_Deck](https://www.ruby-forum.com/u/Mike_Deck)\
**Post date:** [June 30, 2008, 9:59pm UTC](https://www.ruby-forum.com/t/cache-streamed-data/141829/1 "2008-06-30T21:59:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mike\_Deck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc8723/32.png) [@Mike\_Deck](https://www.ruby-forum.com/u/Mike_Deck)\
**Post date:** [June 30, 2008, 10:10pm UTC](https://www.ruby-forum.com/t/cache-streamed-data/141829/2 "2008-06-30T22:10:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mike\_Deck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc8723/32.png) [@Mike\_Deck](https://www.ruby-forum.com/u/Mike_Deck)\
**Post date:** [July 2, 2008, 12:01am UTC](https://www.ruby-forum.com/t/cache-streamed-data/141829/3 "2008-07-02T00:01:27Z")

</div>

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.
