[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 19 Sep 2003 16:53:35 -0000


albertel		Fri Sep 19 12:53:35 2003 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - can now successfully devaildate cache entry
  - courseresdata successfully converted to use caching structure
  - can now cache 'undef' as a value
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.416 loncom/lonnet/perl/lonnet.pm:1.417
--- loncom/lonnet/perl/lonnet.pm:1.416	Fri Sep 19 12:29:09 2003
+++ loncom/lonnet/perl/lonnet.pm	Fri Sep 19 12:53:35 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.416 2003/09/19 16:29:09 albertel Exp $
+# $Id: lonnet.pm,v 1.417 2003/09/19 16:53:35 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -850,21 +850,21 @@
 
 sub devalidate_cache {
     my ($cache,$id) = @_;
-    delete $courseresdatacache{$id.'.time'};
-    delete $courseresdatacache{$id};
+    delete $$cache{$id.'.time'};
+    delete $$cache{$id};
 }
 
 sub is_cached {
     my ($cache,$id,$time) = @_;
     if (!exists($$cache{$id.'.time'})) {
-	return undef;
+	return (undef,undef);
     } else {
-	if (time-$$cache{$id.'.time'}>300) {
-	    &devaidate_cache($cache,$id);
-	    return undef;
+	if (time-$$cache{$id.'.time'}>$time) {
+	    &devalidate_cache($cache,$id);
+	    return (undef,undef);
 	}
     }
-    return $$cache{$id};
+    return ($$cache{$id},1);
 }
 
 sub do_cache {
@@ -878,8 +878,8 @@
     my ($udom,$unam,$courseid)=@_;
     my $hashid="$udom:$unam:$courseid";
     
-    my $result;
-    if ($result=&is_cached(\%usectioncache,$hashid,300)) { return $result; }
+    my ($result,$cached)=&is_cached(\%usectioncache,$hashid,300);
+    if (defined($cached)) { return $result; }
     $courseid=~s/\_/\//g;
     $courseid=~s/^(\w)/\/$1/;
     foreach (split(/\&/,&reply('dump:'.$udom.':'.$unam.':roles',
@@ -3309,27 +3309,23 @@
     my ($coursenum,$coursedomain,@which)=@_;
     my $coursehom=&homeserver($coursenum,$coursedomain);
     my $hashid=$coursenum.':'.$coursedomain;
-    my $dodump=0;
-    if (!defined($courseresdatacache{$hashid.'.time'})) {
-	$dodump=1;
-    } else {
-	if (time-$courseresdatacache{$hashid.'.time'}>300) { $dodump=1; }
-    }
-    if ($dodump) {
+    my ($result,$cached)=&is_cached(\%courseresdatacache,$hashid,300);
+    unless (defined($cached)) {
 	my %dumpreply=&dump('resourcedata',$coursedomain,$coursenum);
+	$result=\%dumpreply;
 	my ($tmp) = keys(%dumpreply);
 	if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
-	    $courseresdatacache{$hashid.'.time'}=time;
-	    $courseresdatacache{$hashid}=\%dumpreply;
+	    &do_cache(\%courseresdatacache,$hashid,$result);
 	} elsif ($tmp =~ /^(con_lost|no_such_host)/) {
 	    return $tmp;
 	} elsif ($tmp =~ /^(error)/) {
-	    $courseresdatacache{$hashid.'.time'}=time;
+	    $result=undef;
+	    &do_cache(\%courseresdatacache,$hashid,$result);
 	}
     }
     foreach my $item (@which) {
-	if (defined($courseresdatacache{$hashid}->{$item})) {
-	    return $courseresdatacache{$hashid}->{$item};
+	if (defined($result->{$item})) {
+	    return $result->{$item};
 	}
     }
     return undef;