version 1.416, 2003/09/19 16:29:09
|
version 1.417, 2003/09/19 16:53:35
|
Line 850 sub getsection {
|
Line 850 sub getsection {
|
|
|
sub devalidate_cache { |
sub devalidate_cache { |
my ($cache,$id) = @_; |
my ($cache,$id) = @_; |
delete $courseresdatacache{$id.'.time'}; |
delete $$cache{$id.'.time'}; |
delete $courseresdatacache{$id}; |
delete $$cache{$id}; |
} |
} |
|
|
sub is_cached { |
sub is_cached { |
my ($cache,$id,$time) = @_; |
my ($cache,$id,$time) = @_; |
if (!exists($$cache{$id.'.time'})) { |
if (!exists($$cache{$id.'.time'})) { |
return undef; |
return (undef,undef); |
} else { |
} else { |
if (time-$$cache{$id.'.time'}>300) { |
if (time-$$cache{$id.'.time'}>$time) { |
&devaidate_cache($cache,$id); |
&devalidate_cache($cache,$id); |
return undef; |
return (undef,undef); |
} |
} |
} |
} |
return $$cache{$id}; |
return ($$cache{$id},1); |
} |
} |
|
|
sub do_cache { |
sub do_cache { |
Line 878 sub usection {
|
Line 878 sub usection {
|
my ($udom,$unam,$courseid)=@_; |
my ($udom,$unam,$courseid)=@_; |
my $hashid="$udom:$unam:$courseid"; |
my $hashid="$udom:$unam:$courseid"; |
|
|
my $result; |
my ($result,$cached)=&is_cached(\%usectioncache,$hashid,300); |
if ($result=&is_cached(\%usectioncache,$hashid,300)) { return $result; } |
if (defined($cached)) { return $result; } |
$courseid=~s/\_/\//g; |
$courseid=~s/\_/\//g; |
$courseid=~s/^(\w)/\/$1/; |
$courseid=~s/^(\w)/\/$1/; |
foreach (split(/\&/,&reply('dump:'.$udom.':'.$unam.':roles', |
foreach (split(/\&/,&reply('dump:'.$udom.':'.$unam.':roles', |
Line 3309 sub courseresdata {
|
Line 3309 sub courseresdata {
|
my ($coursenum,$coursedomain,@which)=@_; |
my ($coursenum,$coursedomain,@which)=@_; |
my $coursehom=&homeserver($coursenum,$coursedomain); |
my $coursehom=&homeserver($coursenum,$coursedomain); |
my $hashid=$coursenum.':'.$coursedomain; |
my $hashid=$coursenum.':'.$coursedomain; |
my $dodump=0; |
my ($result,$cached)=&is_cached(\%courseresdatacache,$hashid,300); |
if (!defined($courseresdatacache{$hashid.'.time'})) { |
unless (defined($cached)) { |
$dodump=1; |
|
} else { |
|
if (time-$courseresdatacache{$hashid.'.time'}>300) { $dodump=1; } |
|
} |
|
if ($dodump) { |
|
my %dumpreply=&dump('resourcedata',$coursedomain,$coursenum); |
my %dumpreply=&dump('resourcedata',$coursedomain,$coursenum); |
|
$result=\%dumpreply; |
my ($tmp) = keys(%dumpreply); |
my ($tmp) = keys(%dumpreply); |
if ($tmp !~ /^(con_lost|error|no_such_host)/i) { |
if ($tmp !~ /^(con_lost|error|no_such_host)/i) { |
$courseresdatacache{$hashid.'.time'}=time; |
&do_cache(\%courseresdatacache,$hashid,$result); |
$courseresdatacache{$hashid}=\%dumpreply; |
|
} elsif ($tmp =~ /^(con_lost|no_such_host)/) { |
} elsif ($tmp =~ /^(con_lost|no_such_host)/) { |
return $tmp; |
return $tmp; |
} elsif ($tmp =~ /^(error)/) { |
} elsif ($tmp =~ /^(error)/) { |
$courseresdatacache{$hashid.'.time'}=time; |
$result=undef; |
|
&do_cache(\%courseresdatacache,$hashid,$result); |
} |
} |
} |
} |
foreach my $item (@which) { |
foreach my $item (@which) { |
if (defined($courseresdatacache{$hashid}->{$item})) { |
if (defined($result->{$item})) { |
return $courseresdatacache{$hashid}->{$item}; |
return $result->{$item}; |
} |
} |
} |
} |
return undef; |
return undef; |