Forum: Ruby on Rails Automatically fill the page cache

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
91308e9bc88cb069fd1bcf88e910d042?d=identicon&s=25 Nick Snels (nicksnels)
on 2008-11-14 00:32
Hi,

I have my whole site cached with page cache, because each page needs
some time to render. What I would like to do is to delete all files in
the cache (I have no problem with that). But after I have deleted
everything, I would like to cache each and every file again, so that my
visitors don't experience any long load times. Any ideas on how to do
this the most efficiently. It's a cache of more than 5.000 pages. Any
ideas are welcome. Thanks.

Kind regards,

Nick
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2008-11-14 03:19
(Received via mailing list)
Hi Nick,

Nick Snels wrote:
> ...after I have deleted everything, I would like to cache each
> and every file again, so that my visitors don't experience any
> long load times. Any ideas on how to do this the most efficiently.

As far as I know, the only way to get a page into the cache is to pull
it
there with a request from a client.  OTOH, the client need _not_ be a
browser.  You could write a script that 'computes' all the possible
requests
(reflecting on controller methods) and then issues them (to the server
through the cache) using Ruby's net/http library.  It's not elegant, and
there're likely to be views that wouldn't get rendered without making
your
script smarter, but it might not be a bad first step.

HTH,
Bill
91308e9bc88cb069fd1bcf88e910d042?d=identicon&s=25 Nick Snels (nicksnels)
on 2008-11-14 09:36
Hi Bill,

thanks for the reply. I already tought of this solution, but this would
mean hammering my own server for a while. Isn't there a more elegant
way, so that the web server is not involved but that Rails handles the
cache generation.

Kind regards,

Nick
27127e68480c1fbf62e6d98a331c3fc6?d=identicon&s=25 Enrico Thierbach (Guest)
on 2008-11-14 12:39
(Received via mailing list)
Well, the web server (eg apache) wouldn't have that much load, would
it? I bet 99% of the load will be in your app anyways.

In terms of traffic I would recommend a locally installed wget or curl
client just pulling everything. And in terms of cpu load: you could
run that script reniced(see "man nice") level, so it doesn't block
incoming requests.

This way your users might have to wait a bit while the page cache
slowly grows, and then you are back at hi speed.

Or else: create an identical instance on a second machine, have the
cache recreated there, copy everything off that machine onto your live
system.

/eno

====================================================================
A wee piece of ruby every monday: http://1rad.wordpress.com/
This topic is locked and can not be replied to.