Is a package global var, such as %CACHE in the code below, persistent during
the life of a child process?  Does each child get a copy of %CACHE after the
parent forks?

Thanks,

Jason
>
> i often do something like this where i allow each individual child
> process to cache it's data.  i do something like this:
>
> package Apache::Foo;
>
> use strict;
> use Apache::Constants;
> use POSIX 'strftime';
>
> use constant CACHE_EXPIRES => 3600; # one hour
> use vars qw[ %CACHE ];
> %CACHE = ();
>
> sub handler {
>     my $r = shift;
>
>     eval {
>         my $expires = $CACHE{'expires'} || 0;
>         if ($expires < time) {
>             my @data = < some routine >;
>             my $t = HTML::Template->new(filename          => 'foo.tmpl',
>                                         die_on_bad_params => 0,
>                                         cache             => 1);
>             $t->param('data', \@data);
>
>             $CACHE{'data'}    = $t->output;
>             $CACHE{'expires'} = time + CACHE_EXPIRES;
>         }
>         $r->print($CACHE{'data'});
>     };
>
>     return print_err($r, $@) if $@;
>     return OK;
> }
>
> 1;
>
> btw, i'd really recommend you look into using Template Toolkit.  it's a
> much more powerful and flexible templating system than HTML::Template,
> but i digress (and might start a flame war against myself by saying this).
>
> hth,
>
> ky
>
>

Reply via email to