古い記事
ランダムジャンプ
新しい記事
CGI + HTML::Template で Cache::File を使うときの自分用メモ、SYNOPSIS。

my $cache_root_root = "/home/yto/www/foobar/cache";
my $cache_page = 
Cache::File->new(cache_root => $cache_root_root."/page",
    cache_umask => 000,
    default_expires => '48 hours',
    size_limit => 10000000,
);

if (defined $cache_page and $key !~ /^\s*$/) {
    my $data = $cache_page->get($key);
    if ($data) {
       print decode('utf8', $data);
       print qq(<!-- cached file -->\n);
       exit;
    }
}

...

my $template = join("", <DATA>);
my $t = HTML::Template->new(scalarref => \$template,
                    loop_context_vars => 1,
                    global_vars => 1,
                    die_on_bad_params => 0);

...

my $out = $t->output();
if ($cache_page and $key !~ /^\s*$/) {
    $cache_page->set($key, $out);
}
print $out;