# Caching for rjs?

**URL:** <https://www.ruby-forum.com/t/caching-for-rjs/153265>\
**Category:** Rails\
**Created:** [November 14, 2008, 4:29am UTC](https://www.ruby-forum.com/t/caching-for-rjs/153265 "2008-11-14T04:29:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [November 14, 2008, 4:29am UTC](https://www.ruby-forum.com/t/caching-for-rjs/153265/1 "2008-11-14T04:29:14Z")

</div>

I am using rjs to perform ajax deletes on objects within an array  
@instructions. The objects within the array @instructions vary  
depending on some other logic in my controller and is not dependent on  
direct correlations within the database. In other words, when I  
update the partial with:

page.replace\_html :instructions, :partial =\>  
‘instructions’, :collection =\> @instructions

The @instructions cannot just be populated by active record  
correlations such as:  
@day.instructions.

The logic used in the controller to populate the @instructions  
variable is expensive and I would prefer not to go through the logic  
again if possible. What is the best option for this situation, would  
using some caching method be best, or is there a way to store the  
@instructions variable in a flash or params or something?

Thanks.

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [November 15, 2008, 2:02am UTC](https://www.ruby-forum.com/t/caching-for-rjs/153265/2 "2008-11-15T02:02:20Z")

</div>

David wrote:

> correlations such as:  
> @day.instructions.
> 
> The logic used in the controller to populate the @instructions  
> variable is expensive and I would prefer not to go through the logic  
> again if possible. What is the best option for this situation, would  
> using some caching method be best, or is there a way to store the  
> @instructions variable in a flash or params or something?

Probably the best way would be to cache the whole HTML  
partial using Rails’ partial-cache capability. You would  
use a custom cache key that’s built on the set of controller  
parameters that influence the contents of the @instructions  
collection.

–  
Rails Wheels - Find Plugins, List & Sell Plugins -  
[http://railswheels.com](http://railswheels.com)

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [November 15, 2008, 1:04pm UTC](https://www.ruby-forum.com/t/caching-for-rjs/153265/3 "2008-11-15T13:04:58Z")

</div>

OK, thanks. I actually solved the problem by just deleting the html  
with: page[dom\_id(@instruction)].remove.
