Caching a hash - am I missing something?
am 20.08.2008 01:35:29 von Chris FaustThis is a multi-part message in MIME format.
------=_NextPart_000_0321_01C90232.BE331950
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Hi,
This might be a little off topic, I hope it's OK to post. I'm not positive
if mod_perl matters or not because it's a little confusing to me.
I've taken over some pretty old code that I'm updating and making mp2
content handlers out of. The main script is a standard cgi script
"start.cgi" there is nothing special in the apache conf for it.
SetHandler perl-script
PerlFixupHandler My::Fixup
PerlResponseHandler ModPerl::PerlRun
PerlOptions +ParseHeaders
DirectoryIndex start.cgi
Options +ExecCGI +Indexes
allow from all
start.cgi calls a custom module (use CustomModule;) which exports a bunch of
subs, for example foobar and all over the place in the subs that are
exported from CustomModule I see code like
sub foobar {
my $key = @_;
if ($cache{$key}) {
return $cache{$key};
} else {
my $do_some_query = xxxx;
$cache{$key} = $do_some_query_results
return $cache{$key};
}
}
My question is isn't the "else" in foobar always going to be true anyplace
where start.cgi is calling "&foobar('somekey')"??????
I don't understand how %cache could already be populate from a previous
browser request or something? I'm I just missing something stupid?
FYI this was all running before on a version of Debian with old apache and
old mod_perl (early 1.99 and 2.0.x). I've updated mod_perl to 2.0.2 and
apache to 2.2 and everything still works.
TIA!!
-Chris
------=_NextPart_000_0321_01C90232.BE331950
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
xmlns=3D"http://www.w3.org/TR/REC-html40">
charset=3Dus-ascii">
style=3D'font-size:10.0pt;
font-family:Arial'>Hi,
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'>This might be a little off topic, I hope it’s =
OK to
post. I’m not positive if mod_perl matters or not because =
it’s a little
confusing to me.
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'>I’ve taken over some pretty old code that =
I’m updating
and making mp2 content handlers out of. The main script is a standard =
cgi
script “start.cgi” there is nothing special in the apache =
conf for
it.
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'> =
<Directory /xxx/>
style=3D'font-size:10.0pt;
font-family:Arial'> SetHandler
perl-script
style=3D'font-size:10.0pt;
font-family:Arial'> =
PerlFixupHandler
My::Fixup
style=3D'font-size:10.0pt;
font-family:Arial'>
PerlResponseHandler ModPerl::PerlRun
style=3D'font-size:10.0pt;
font-family:Arial'> =
PerlOptions
+ParseHeaders
style=3D'font-size:10.0pt;
font-family:Arial'> =
DirectoryIndex start.cgi
style=3D'font-size:10.0pt;
font-family:Arial'> Options =
+ExecCGI
+Indexes
style=3D'font-size:10.0pt;
font-family:Arial'> allow from =
all
style=3D'font-size:10.0pt;
font-family:Arial'>
</Directory>
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'>start.cgi calls a custom module (use CustomModule;) =
which
exports a bunch of subs, for example foobar and all over the place in =
the subs
that are exported from CustomModule I see code =
like
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'>sub foobar {
style=3D'font-size:10.0pt;
font-family:Arial'> =
my
$key =3D @_;
style=3D'font-size:10.0pt;
font-family:Arial'> =
style=3D'font-size:10.0pt;
font-family:Arial'> =
if
($cache{$key}) {
style=3D'font-size:10.0pt;
font-family:Arial'> =
&=
nbsp; return
$cache{$key};
style=3D'font-size:10.0pt;
font-family:Arial'> =
}
else {
style=3D'font-size:10.0pt;
font-family:Arial'> =
&=
nbsp; my
$do_some_query =3D xxxx;
style=3D'font-size:10.0pt;
font-family:Arial'> =
&=
nbsp; $cache{$key}
=3D $do_some_query_results
style=3D'font-size:10.0pt;
font-family:Arial'> =
&=
nbsp; return
$cache{$key};
style=3D'font-size:10.0pt;
font-family:Arial'> =
}
style=3D'font-size:10.0pt;
font-family:Arial'>}
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'>My question is isn’t the “else” in =
foobar
always going to be true anyplace where start.cgi is calling =
“&foobar(‘somekey’)”??????
/font>
style=3D'font-size:10.0pt;
font-family:Arial'>I don’t understand how %cache could already be
populate from a previous browser request or something? I’m I just =
missing
something stupid?
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'>FYI this was all running before on a version of =
Debian with old
apache and old mod_perl (early 1.99 and 2.0.x). I’ve updated =
mod_perl to 2.0.2
and apache to 2.2 and everything still =
works.
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'>TIA!!
style=3D'font-size:10.0pt;
font-family:Arial'>-Chris
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'>
style=3D'font-size:10.0pt;
font-family:Arial'>
------=_NextPart_000_0321_01C90232.BE331950--