views:

175

answers:

1

Hey Everyone,

Our initial page load is a beast in our Rails app. The great thing about it is the lack of page refreshes needed. The whole thing is very Ajax-y (and our designers made it look great!) There is only one problem: Initial page load is a monster.

I have tweaked and prodded and have eeked out incredible speed improvements by optimizing, cacheing, memoizing, etc. For typical users of my app, the whole thing is very usable. However there are edge cases where the amount of data being crunched is significantly more then others and initial page load can take up to 15-25 seconds due to sheer amount of data being crunched.

Our biggest problem is that we can't page cache anything. The application in question is very CREATE/UPDATE heavy and users only come to it when they need to make changes, a quick parse of our logs show PUTs and POSTs outnumber GET's almost 50 to 1. Any attempt to page cache, action, or fragment cache any parts of the page would expire almost immediately, which has made performance a bit difficult to improve now that all of the other layers are optimized. What I am wondering is this:

Is there a way for me to generate the page and "pre-warm" the cache with it so that when the page is requested I serve it from the cache instead of the application? What I have in my mind is while the user is PUTing and POSTing using the existing page (this all happens with xhr requests) my server can expire and regenerate the page server side so that when it comes time for the user to request the full page again ... BAM it is already generated and I am serving it up. Obviously this will be taking up some significant system resources, but I am lucky in my fantastic hardware and have a finite amount of users.

From a logical standpoint it seems like what I am must have been done before, however I can't seem to find any examples of it on the 'net . . . could just be typing the wrong words though. Any ideas? Examples? Tutorials, plugins or links I can follow?

Thanks ahead of time! Really appreciate it!

A: 

I don't know of any existing plugins or gems to handle this for you.

But you can find plenty on expiring cached content when saving models, and at worst you could have an additional hook in your after_save that (once the cached content is expired) hits the url that would generate that cache internally.

pseudo-code:

clear_cache
# get the page (in which the page is cached)
open("http://localhost/controller_name/#{id}").read

I'm not saying that's the way to do it, but it would at least technically work.

semanticart