As I mentioned - this code has been running fine in a production server for 18 months or more - the previous code definitely worked.

I'm quite willing to believe there is something else in the environment that is getting in the way - I was just very surprised (and, happily, judging by ppls reactions so far, so are they) that the my() variable wasn't filled in.

And, yes, I've tested that fill_cache gets values and puts them into %cache. The problem is that the values don't hang around once fill_cache() returns. I don't know why :-)

Output from full code below is here. First set of statements is with my(), second with our(). Full apache restart just before each request.

A normal request involves hitting the cache for password then again for a list of allowed groups (in two separate Auth* handlers) and checking against the Apache require group directive. You can see that the group lookup isn't even mentioned on the successful run as it is already cached.

[18981] get_pass: not in cache - retrieving [18981] fill_cache: setting cache [andrewo] pw:[andrewo] groups:[enabl +ed] [18981] get_pass: password now: andrewo [18981] get_groups: not in cache - retrieving [18981] fill_cache: setting cache [andrewo] pw:[andrewo] groups:[enabl +ed] [18981] get_groups: groups now: user undef! [Tue Sep 20 17:15:51 2005] [error] Can't use an undefined value as an +ARRAY reference at /usr/local/share/perl/5.8.4/Oriel/Apache/UserCache.pm line 56.\n [19054] get_pass: not in cache - retrieving [19054] fill_cache: setting cache [andrewo] pw:[andrewo] groups:[enabl +ed] [19054] get_pass: password now: andrewo
And the full UserCache module (with added warns):
package My::Apache::UserCache; use strict; use Apache::Constants qw(:common); use My::User; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw(get_pass get_groups); use constant CACHE_TIMEOUT => 60; # seconds # # username => { timestamp => unixtime, # password => blah, # groups => [groups], }, # our %cache = (); sub fill_cache { my $user = shift; my $now = time; my ($password, @groups) = Oriel::User->get_pw_groups($user ); # enforce at least 1 character passwords return 0 unless defined $password && length($password); warn "[$$] fill_cache: setting cache [$user] pw:[$password] groups:[ +".join(',',@groups)."]\n"; $cache{$user} = { timestamp => $now, password => $password, groups => [@groups] }; } sub get_pass { my $user = shift; my $now = time; return $cache{$user}->{password} if ( exists $cache{$user} && $cache{$user}->{timestamp} && ($now - $cache{$user}->{timestamp}) < CACHE_TIMEOUT ); warn "[$$] get_pass: not in cache - retrieving\n"; return undef unless fill_cache( $user ); warn "[$$] get_pass: password now: ".(defined cache{$user} ? $cache{ +$user}->{password} : 'user undef!')."\n"; $cache{$user}->{password}; } sub get_groups { my $user = shift; my $now = time; return @{$cache{$user}->{groups}} if ( exists $cache{$user} && $cache{$user}->{timestamp} && ($now - $cache{$user}->{timestamp}) < CACHE_TIMEOUT ); warn "[$$] get_groups: not in cache - retrieving\n"; return () unless fill_cache( $user ); warn "[$$] get_groups: groups now: ".(defined $cache{$user} ? @{$cac +he{$user}->{groups}} : 'user undef!')."\n"; @{$cache{$user}->{groups}}; } 1;

Its weird. Any ideas?


In reply to Re^2: package scoped my() variable in module under mod_perl 5.6 vs 5.8 by njaph
in thread package scoped my() variable in module under mod_perl 5.6 vs 5.8 by njaph

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.