[Catalyst] V::TT dynamic --> truly static
apv
apv at sedition.com
Fri Nov 11 02:05:59 CET 2005
Answering my own question from a couple weeks back, looking for a
little code sanity check or feedback or just to share if it seems sound.
This is what I've ended up doing in my base class:
sub end : Private {
my ( $self, $c ) = @_;
unless ( $c->res->output ) {
$c->forward('MyApp::V::TT');
if ( $c->stash->{write_static_file} ) {
require File::Path;
require File::Spec;
my $path = File::Spec->catfile(
$c->config->{webroot},
$c->req->path
);
my ( $vol, $dir, $file) = File::Spec->splitpath( $path );
File::Path::mkpath([$dir], 0, 0777) unless -d $dir;
open my $file, '>', $path or die "$!: $path";
binmode $file;
print $file $c->res->output;
close $file or warn "Problem closing $file: $!";
}
}
}
That way I can write a static file by setting
"$c->stash->{write_static_file} = 1" in any part of any handler.
Any improvements or feedback?
(The reason I'm using this solution instead of caching is the webhost
in question has a pretty big penalty for process time but gives almost
unlimited file serving.)
On Saturday, October 15, 2005, at 02:58 PM, apv wrote:
> I'm trying to set up an application that has the best of both words:
> serve initial requests for a resource dynamically but write the viewed
> page out to a file so that all subsequent requests for the file get a
> real file and don't bother the Catalyst dispatcher at all. To update a
> page that gets out of sync with data, just delete the file and it will
> get rewritten on the next request.
>
> I'm setting it up via Apache to check for file existence and if it's
> not found, pass the request to Catalyst.
>
> RewriteEngine on
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteRule ^(.+)$ /index.pl [L]
>
> So, that's all well and good but how should I (how would you) do the
> Template part of writing the file out? I've done this in the past from
> within TT with things like this snippet:
>
> [[ FILTER redirect( file ) ]]
> [[ INCLUDE 'page-wrapper'
> article = art.name ]]
> [[ END ]]
>
> Would it be wise to keep it in the template files or move it somewhere
> into the View? Has anyone tackled this already?
>
> Thank you!
> -Ashley
>
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>
>
More information about the Catalyst
mailing list