Diff for /loncom/lonnet/perl/lonnet.pm between versions 1.523.2.3 and 1.523.2.7

version 1.523.2.3, 2004/09/15 20:44:05 version 1.523.2.7, 2004/09/24 15:51:11
Line 826  my $disk_caching_disabled=1; Line 826  my $disk_caching_disabled=1;
 sub devalidate_cache {  sub devalidate_cache {
     my ($cache,$id,$name) = @_;      my ($cache,$id,$name) = @_;
     delete $$cache{$id.'.time'};      delete $$cache{$id.'.time'};
       delete $$cache{$id.'.file'};
     delete $$cache{$id};      delete $$cache{$id};
     if (1 || $disk_caching_disabled) { return; }      if (1 || $disk_caching_disabled) { return; }
     my $filename=$perlvar{'lonDaemons'}.'/tmp/lonnet_internal_cache_'.$name.".db";      my $filename=$perlvar{'lonDaemons'}.'/tmp/lonnet_internal_cache_'.$name.".db";
Line 857  sub is_cached { Line 858  sub is_cached {
     my ($cache,$id,$name,$time) = @_;      my ($cache,$id,$name,$time) = @_;
     if (!$time) { $time=300; }      if (!$time) { $time=300; }
     if (!exists($$cache{$id.'.time'})) {      if (!exists($$cache{$id.'.time'})) {
  &load_cache_item($cache,$name,$id);   &load_cache_item($cache,$name,$id,$time);
     }      }
     if (!exists($$cache{$id.'.time'})) {      if (!exists($$cache{$id.'.time'})) {
 # &logthis("Didn't find $id");  # &logthis("Didn't find $id");
  return (undef,undef);   return (undef,undef);
     } else {      } else {
  if (time-($$cache{$id.'.time'})>$time) {   if (time-($$cache{$id.'.time'})>$time) {
 #    &logthis("Devalidating $id - ".time-($$cache{$id.'.time'}));      if (exists($$cache{$id.'.file'})) {
     &devalidate_cache($cache,$id,$name);   foreach my $filename (@{ $$cache{$id.'.file'} }) {
     return (undef,undef);      my $mtime=(stat($filename))[9];
       #+1 is to take care of edge effects
       if ($mtime && (($mtime+1) < ($$cache{$id.'.time'}))) {
   # &logthis("Upping $mtime - ".$$cache{$id.'.time'}.
   # "$id because of $filename");
       } else {
   # &logthis("Devalidating $filename $id - ".(time-($$cache{$id.'.time'})));
    &devalidate_cache($cache,$id,$name);
    return (undef,undef);
       }
    }
    $$cache{$id.'.time'}=time;
       } else {
   # &logthis("Devalidating $id - ".time-($$cache{$id.'.time'}));
    &devalidate_cache($cache,$id,$name);
    return (undef,undef);
       }
  }   }
     }      }
     return ($$cache{$id},1);      return ($$cache{$id},1);
Line 910  sub save_cache { Line 927  sub save_cache {
  eval <<'EVALBLOCK';   eval <<'EVALBLOCK';
  $hash{$id.'.time'}=$$cache{$id.'.time'};   $hash{$id.'.time'}=$$cache{$id.'.time'};
  $hash{$id}=freeze({'item'=>$$cache{$id}});   $hash{$id}=freeze({'item'=>$$cache{$id}});
    if (exists($$cache{$id.'.file'})) {
       $hash{$id.'.file'}=freeze({'item'=>$$cache{$id.'.file'}});
    }
 EVALBLOCK  EVALBLOCK
                 if ($@) {                  if ($@) {
     &logthis("<font color='red'>save_cache blew up :$@:$name</font>");      &logthis("<font color='red'>save_cache blew up :$@:$name</font>");
Line 934  EVALBLOCK Line 954  EVALBLOCK
 }  }
   
 sub load_cache_item {  sub load_cache_item {
     my ($cache,$name,$id)=@_;      my ($cache,$name,$id,$time)=@_;
     if ($disk_caching_disabled) { return; }      if ($disk_caching_disabled) { return; }
     my $starttime=&Time::HiRes::time();      my $starttime=&Time::HiRes::time();
 #    &logthis("Before Loading $name  for $id size is ".scalar(%$cache));  #    &logthis("Before Loading $name  for $id size is ".scalar(%$cache));
Line 958  sub load_cache_item { Line 978  sub load_cache_item {
  }   }
 #    &logthis("Initial load: $count");  #    &logthis("Initial load: $count");
     } else {      } else {
  my $hashref=thaw($hash{$id});   if (($$cache{$id.'.time'}+$time) < time) {
  $$cache{$id}=$hashref->{'item'};      $$cache{$id.'.time'}=$hash{$id.'.time'};
  $$cache{$id.'.time'}=$hash{$id.'.time'};      {
    my $hashref=thaw($hash{$id});
    $$cache{$id}=$hashref->{'item'};
       }
       if (exists($hash{$id.'.file'})) {
    my $hashref=thaw($hash{$id.'.file'});
    $$cache{$id.'.file'}=$hashref->{'item'};
       }
    }
     }      }
 EVALBLOCK  EVALBLOCK
         if ($@) {          if ($@) {
Line 3104  sub log_query { Line 3132  sub log_query {
 sub fetch_enrollment_query {  sub fetch_enrollment_query {
     my ($context,$affiliatesref,$replyref,$dom,$cnum) = @_;      my ($context,$affiliatesref,$replyref,$dom,$cnum) = @_;
     my $homeserver;      my $homeserver;
       my $maxtries = 1;
     if ($context eq 'automated') {      if ($context eq 'automated') {
         $homeserver = $perlvar{'lonHostID'};          $homeserver = $perlvar{'lonHostID'};
           $maxtries = 10; # will wait for up to 2000s for retrieval of classlist data before timeout
     } else {      } else {
         $homeserver = &homeserver($cnum,$dom);          $homeserver = &homeserver($cnum,$dom);
     }      }
Line 3120  sub fetch_enrollment_query { Line 3150  sub fetch_enrollment_query {
     my $queryid=&reply("querysend:".$query.':'.$dom.':'.$ENV{'user.name'}.':'.$cmd,$homeserver);      my $queryid=&reply("querysend:".$query.':'.$dom.':'.$ENV{'user.name'}.':'.$cmd,$homeserver);
     unless ($queryid=~/^\Q$host\E\_/) { return 'error: '.$queryid; }      unless ($queryid=~/^\Q$host\E\_/) { return 'error: '.$queryid; }
     my $reply = &get_query_reply($queryid);      my $reply = &get_query_reply($queryid);
       my $tries = 1;
       while (($reply=~/^timeout/) && ($tries < $maxtries)) {
    $reply = &get_query_reply($queryid);
    $tries++;
       }
       if ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
    &logthis('fetch_enrollment_query error: '.$reply.' for '.$dom.' '.
    $ENV{'user.name'}.' for '.$queryid.' context: '.$context.' '.
    $cnum.' maxtries: '.$maxtries.' tries: '.$tries);
       }
     unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {      unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
         my @responses = split/:/,$reply;          my @responses = split/:/,$reply;
         if ($homeserver eq $perlvar{'lonHostID'}) {          if ($homeserver eq $perlvar{'lonHostID'}) {
Line 4225  sub metadata { Line 4265  sub metadata {
         unless ($filename=~/\.meta$/) { $filename.='.meta'; }          unless ($filename=~/\.meta$/) { $filename.='.meta'; }
  my $metastring;   my $metastring;
  if ($uri !~ m|^uploaded/|) {   if ($uri !~ m|^uploaded/|) {
     $metastring=&getfile(&filelocation('',&clutter($filename)));      my $file=&filelocation('',&clutter($filename));
       push(@{$metacache{$uri.'.file'}},$file);
       $metastring=&getfile($file);
  }   }
         my $parser=HTML::LCParser->new(\$metastring);          my $parser=HTML::LCParser->new(\$metastring);
         my $token;          my $token;
Line 4590  sub deversion { Line 4632  sub deversion {
   
 sub symbread {  sub symbread {
     my ($thisfn,$donotrecurse)=@_;      my ($thisfn,$donotrecurse)=@_;
     if (defined($ENV{'request.symbread.cached'})) {      my $cache_str='request.symbread.cached.'.$thisfn;
  return $ENV{'request.symbread.cached'};      if (defined($ENV{$cache_str})) { return $ENV{$cache_str}; }
     }  
 # no filename provided? try from environment  # no filename provided? try from environment
     unless ($thisfn) {      unless ($thisfn) {
         if ($ENV{'request.symb'}) {          if ($ENV{'request.symb'}) {
     $ENV{'request.symbread.cached'}=&symbclean($ENV{'request.symb'});      return $ENV{$cache_str}=&symbclean($ENV{'request.symb'});
     return $ENV{'request.symbread.cached'};  
  }   }
  $thisfn=$ENV{'request.filename'};   $thisfn=$ENV{'request.filename'};
     }      }
 # is that filename actually a symb? Verify, clean, and return  # is that filename actually a symb? Verify, clean, and return
     if ($thisfn=~/\_\_\_\d+\_\_\_(.*)$/) {      if ($thisfn=~/\_\_\_\d+\_\_\_(.*)$/) {
  if (&symbverify($thisfn,$1)) {   if (&symbverify($thisfn,$1)) {
     $ENV{'request.symbread.cached'}=&symbclean($thisfn);      return $ENV{$cache_str}=&symbclean($thisfn);
     return $ENV{'request.symbread.cached'};  
  }   }
     }      }
     $thisfn=declutter($thisfn);      $thisfn=declutter($thisfn);
Line 4627  sub symbread { Line 4666  sub symbread {
            unless ($syval=~/\_\d+$/) {             unless ($syval=~/\_\d+$/) {
        unless ($ENV{'form.request.prefix'}=~/\.(\d+)\_$/) {         unless ($ENV{'form.request.prefix'}=~/\.(\d+)\_$/) {
                   &appenv('request.ambiguous' => $thisfn);                    &appenv('request.ambiguous' => $thisfn);
   $ENV{'request.symbread.cached'}='';    return $ENV{$cache_str}='';
                   return '';  
                }                     }    
                $syval.=$1;                 $syval.=$1;
    }     }
Line 4675  sub symbread { Line 4713  sub symbread {
            }             }
         }          }
         if ($syval) {          if ($syval) {
     $ENV{'request.symbread.cached'}=&symbclean($syval.'___'.$thisfn);      return $ENV{$cache_str}=&symbclean($syval.'___'.$thisfn);
     return $ENV{'request.symbread.cached'};  
         }          }
     }      }
     &appenv('request.ambiguous' => $thisfn);      &appenv('request.ambiguous' => $thisfn);
     $ENV{'request.symbread.cached'}='';      return $ENV{$cache_str}='';
     return '';  
 }  }
   
 # ---------------------------------------------------------- Return random seed  # ---------------------------------------------------------- Return random seed

Removed from v.1.523.2.3  
changed lines
  Added in v.1.523.2.7


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>