This post originated from an RSS feed registered with Ruby Buzz
by Guy Naor.
Original Post: Ajax and Caching
Feed Title: Famundo - The Dev Blog
Feed URL: http://devblog.famundo.com/xml/rss/feed.xml
Feed Description: A blog describing the development and related technologies involved in creating famundo.com - a family management sytem written using Ruby On Rails and postgres
Sorry I didn't write for so long... Too busy working, I guess.
I wrote a tiny help system for Famundo. It's like a VERY oppinionated CMS ;-).
It's wiki like for entering the help pages, and uses caching for serving out the pages to the users. I'll have more details about, and if anyone is interested, we have plans for open sourcing it.
I was using some Ajax to display the pages, but then discovered that Ajax and caching are not too friendly to each other.
Caching in rails works only for GET out of the box, and Ajax calls are POST by default. So I changed that to POST using :method => :get in link_to_remote.
But this brings a new problem - any AJAX call that uses RJS templates, or the
render :update do |page|
end
methods will fail with page caching, as the Ajax caller expects the returned content to be of type text/javascript, but after being cached to a page, the content type returned by the server will be text/html, and the Ajax listener won't handle it correctly.
The option we have for handling this is either to find a way for the webserver server to serve different file (and we will have to save the files with the correct extension), or use fragment caching.
It works perfectly with fragments, but then caching isn't as aggressive, because for every call the rails process still needs to be called.