About the author.

Welcome to datsoc.com

My own brand of technical mumbo jumbo Read more...

For the record, this blog is not intended to be a source of technical support, political rants, or personal ramblings. I need a place to store my technical thoughts where my family and friends don't have to wade through the jargon, and this is my answer. Think of it as my public personal organization center for all things technical. I hope you find it somewhat useful too, however that is in no way my guarantee.

May
23
2007
10:59 am
Tags:
Post Meta :

To make short 45 minutes of frustration… Yes it is possible to fragment cache your rjs data. The only difficulty is that you can’t do it within RJS.

If you can’t bring a horse to water you bring water to the horse.

So at this point I toyed with the idea of renderng rjs templates *within* rhtml templates. The first barrier to entry is the return type, but you can fix that by changing the header in your controller, before you render:

@headers["Content-Type"] = 'text/javascript'
render :action=>"index_render_rjs", :layout=>false

By rendering an rhtml template this gives you the ability to cache inline. I tried a couple theories on how to render rjs in my rhtml template and the following worked for me:

<% cache("token") do -%>
<% prepare_data() %>
<%= render :update do |page|
page.call("Something")
page.visual_effect :appear, 'a_field'
end%>
<%end%>

This put together works pretty well.

The only reason to do this is if you push your sql calls into the cached section of the page so that they aren’t executed when the page is cached. This is breaking with MVC and a memcache solution is probably semantically superior, but this works too and makes the whole process a lot faster.

Participate! Leave your comment.