in reply to Caching data with mod_perl
And use it by doingsub CheckCache { my $self = shift; my $sub = shift; my $subref = shift; my $time = shift; if (not defined($subtimes{$sub}) or $subtimes{$sub}) < time - $time +) { $self->newsub($subref,$sub,$time);} else {goto &$sub;} } sub newsub { my $self = shift; ref $self or die("$self is not an object"); my $subref = shift; my $sub = shift; my $time = shift; $subtimes{$sub} = $time; *$sub = &$subref; # no reason to play this game every time goto &$sub; }
Note: For non OO, $self should not be included, and lines with $self are probably not necessary. Personally, I would use OO for this task, because I think it would be easier to expand, however it is *your choice*.my $cache = new Cache::Cache; $cache->CheckCache("key",\&sub,$time); # Object oriented Or Cache::CheckCache("key",\&sub,$time); # in non OO
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Caching data with mod_perl
by flocto (Pilgrim) on Jul 14, 2002 at 09:15 UTC | |
by perrin (Chancellor) on Jul 14, 2002 at 21:56 UTC | |
by caedes (Pilgrim) on Jul 15, 2002 at 04:07 UTC | |
|
Re: Re: Caching data with mod_perl
by caedes (Pilgrim) on Jul 14, 2002 at 02:56 UTC | |
by chromatic (Archbishop) on Jul 14, 2002 at 07:38 UTC | |
by Aristotle (Chancellor) on Jul 15, 2002 at 15:39 UTC | |
|
Re: Re: Caching data with mod_perl
by caedes (Pilgrim) on Jul 14, 2002 at 03:13 UTC |