# Gruff Caching?

**URL:** <https://www.ruby-forum.com/t/gruff-caching/95331>\
**Category:** Rails\
**Created:** [December 5, 2005, 8:09pm UTC](https://www.ruby-forum.com/t/gruff-caching/95331 "2005-12-05T20:09:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![a.filipowski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@a.filipowski](https://www.ruby-forum.com/u/a.filipowski)\
**Post date:** [December 5, 2005, 8:09pm UTC](https://www.ruby-forum.com/t/gruff-caching/95331/1 "2005-12-05T20:09:05Z")

</div>

I have a partial that I am rendering that contains several graphs  
generated by gruff. These graphs are displaying data points pulled  
from my database, and I want to allow the user to change the  
datapoints (filter based on criteria). I have the graphs being  
written into a directory and I have the filter actions set up to  
redraw the graphs which is getting done (if I look at the directory  
the graphs are put into the files are being replaced with the new  
graphs) but the browser is not redrawing the partial after I update  
the graphs. I am calling the graphs via an image tag. The filter is  
being set by a form\_remote\_tag. My question really is how do I force  
a partial to redraw everything no matter what.

Andrew

---

<div class="post-metadata">

**Author:** ![a.filipowski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@a.filipowski](https://www.ruby-forum.com/u/a.filipowski)\
**Post date:** [December 5, 2005, 8:21pm UTC](https://www.ruby-forum.com/t/gruff-caching/95331/2 "2005-12-05T20:21:26Z")

</div>

generating a new, unique graph file name everytime the data is changed  
should do it.

---

<div class="post-metadata">

**Author:** ![a.filipowski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@a.filipowski](https://www.ruby-forum.com/u/a.filipowski)\
**Post date:** [December 6, 2005, 4:05am UTC](https://www.ruby-forum.com/t/gruff-caching/95331/3 "2005-12-06T04:05:25Z")

</div>

Lou V. \<vanek@…\> writes:

> generating a new, unique graph file name everytime the data is changed should  
> do it.
> 
> > is not redrawing the partial after I update the graphs. I am calling  
> > the graphs via an image tag. The filter is being set by a  
> > form\_remote\_tag. My question really is how do I force a partial to  
> > redraw everything no matter what.
> > 
> > Andrew

Another option is to send the graph data to the browser directly rather  
than  
writing it to disk. Not the most efficient practice but not necessarily  
bad if  
your data source changes constantly.

def make\_graph  
g = Gruff::Line.new  
…  
send\_data(g.to\_blob, :filename =\> “ck.png”, :type =\> ‘image/png’,  
:disposition  
=\> ‘inline’)  
end

Then you can just invoke the controller method directly in your image  
source:

![](https://www.ruby-forum.com/controller/make_graph)

---

<div class="post-metadata">

**Author:** ![a.filipowski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@a.filipowski](https://www.ruby-forum.com/u/a.filipowski)\
**Post date:** [December 6, 2005, 9:09pm UTC](https://www.ruby-forum.com/t/gruff-caching/95331/4 "2005-12-06T21:09:41Z")

</div>

there’s also the ‘no-cache’ header directive,  
[http://www.htmlgoodies.com/beyond/reference/article.php/3472881](http://www.htmlgoodies.com/beyond/reference/article.php/3472881)

---

<div class="post-metadata">

**Author:** ![a.filipowski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@a.filipowski](https://www.ruby-forum.com/u/a.filipowski)\
**Post date:** [December 6, 2005, 8:53pm UTC](https://www.ruby-forum.com/t/gruff-caching/95331/5 "2005-12-06T20:53:15Z")

</div>

On Dec 5, 2005, at 9:56 PM, Tyler K. wrote:

> …  
> send\_data(g.to\_blob, :filename =\> “ck.png”, :type =\> ‘image/  
> png’, :disposition  
> =\> ‘inline’)  
> end
> 
> Then you can just invoke the controller method directly in your  
> image source:
> 
> ![](https://www.ruby-forum.com/controller/make_graph)

hm, I tried this before I asked the question but perhaps I did  
something wrong. I am writing multiple graphs to the page and kept  
getting a multiple render error which made me go the route of writing  
the graphs to disk.

Andrew

---

<div class="post-metadata">

**Author:** ![a.filipowski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@a.filipowski](https://www.ruby-forum.com/u/a.filipowski)\
**Post date:** [April 3, 2007, 5:42pm UTC](https://www.ruby-forum.com/t/gruff-caching/95331/6 "2007-04-03T17:42:21Z")

</div>

Sorry to bump such an old topic, but I’ve run in to much the same  
problem. I’m rendering a partial which is re-rendered every so often  
using AJAX. Both suggestions mentioned above don’t appear to work  
(changing the filename sent with each request and calling the controller  
directly). I’ve also used a simple method to alter HTTP headers with  
pragma and no-cache, all to no avail.

Does anyone have any other suggestions?

For reference, here’s some snippets:

Gruff controller:  
send\_data(g.to\_blob, :disposition =\> ‘inline’, :type =\> ‘image/png’)

View:  
 ![]()
