Martin Ellison wrote:
I actually want to save a static copy of the front page to improve load times. My fastcgi process sometimes disappears (I'm on shared hosting and I think they auto-cancel stale processes), and it takes a while for the process to be restarted, which impacts the first page load. Subsequent pages are faster but it's the first page that makes the impression on the user. The static plugin does not work, because that requires fastcgi to be running, and my app is too small for me to set up squid.

So I want to redirect the front page to a static page, but regenerate the static page, and also force the app to do something (so the server can restart the fastcgi process before the user requests any other page).


We do exactly this for our app and it's a lifesaver when hit with a Slashdotting. Our app is 99% read / 1% write so using a lightweight HTTP server (Lighttpd, NginX, etc) in front of the FastCGI Catalyst app makes for amazing scalability.

To do this, we have something like this in our Root controller:

sub render : ActionClass('RenderView') {}
sub end : Private {
    my ( $self, $c ) = @_;

    $c->forward('render');
    if ($c->stash->{save_response_as}) {
        File::Slurp::write_file(
            $c->stash->{save_response_as},
            { atomic => 1, buf_ref => \$c->res->body }
        );
    }
}

Then you can use some -f style rules in apache or lighttpd to serve the file if it exists. On the (relatively) rare occasion of a write request we simple delete the files from the cache.

Hope that helps!
- Brian

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to