mr.nick has asked for the wisdom of the Perl Monks concerning the following question:
and expect $x to be dynamic. This I understand. What I don't understand is how to accomplish something.sub outer { my $x; $x=shift; sub inner { print "x is $x\n"; } }
The concept is that regardless of how many instances of Node:: that you create, the same Cache:: object will be used to improve performance.package Node; use Cache; my $cache=new Cache; sub new { ## blah blah $self; } sub get { my $self=shift; my $id=shift; if (my $data=$cache->check($id)) { return $data; } ## blah blah } 1;
This is wonderful until I converted the app to work under mod_perl. Now I can't figure out a way of maintaining a single cache for all instances.
Using use vars qw($cache) is fine to preserve the dynamic nature of $cache, but it keeps the $cache object alive across invocations of CGI (which is A Bad Thing because another thread might have modified the object and this instance has no knowledge of it).
What I want is for $cache to behave like it would under a normal CGI; it's created at the beginning of the execution of the script and dies at the end.
If this was in the main cgi-bin and not a class, I could do something like:
But this won't work inside a module (because mod_perl only executes the class once when loading it for the first time).{ $cache=new Cache; } ## everything { undef $cache; }
Assuming this was moderately understandable (which I doubt), does anyone have any suggestions or ideas?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: Regarding variables that
by tilly (Archbishop) on Mar 05, 2001 at 09:47 UTC | |
|
(dkubb) Re: (2) Persistent Variables
by dkubb (Deacon) on Mar 05, 2001 at 12:38 UTC | |
by mr.nick (Chaplain) on Mar 13, 2001 at 18:58 UTC |