[LON-CAPA-cvs] cvs: loncom(version_1_3_X_memcached) /lonnet/perl lonnet.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Sun, 13 Feb 2005 23:09:03 -0000
albertel Sun Feb 13 18:09:03 2005 EDT
Modified files: (Branch: version_1_3_X_memcached)
/loncom/lonnet/perl lonnet.pm
Log:
- converting titlecache to memcached, genralizing the memcache code a bit
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.587.2.3.2.2 loncom/lonnet/perl/lonnet.pm:1.587.2.3.2.3
--- loncom/lonnet/perl/lonnet.pm:1.587.2.3.2.2 Sun Feb 13 17:12:34 2005
+++ loncom/lonnet/perl/lonnet.pm Sun Feb 13 18:09:03 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.587.2.3.2.2 2005/02/13 22:12:34 albertel Exp $
+# $Id: lonnet.pm,v 1.587.2.3.2.3 2005/02/13 23:09:03 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,7 +36,7 @@
# use Date::Parse;
use vars
qw(%perlvar %hostname %homecache %badServerCache %hostip %iphost %spareid %hostdom
- %libserv %pr %prp $metacache %packagetab %titlecache %courseresversioncache %resversioncache
+ %libserv %pr %prp $memcache %packagetab %courseresversioncache %resversioncache
%courselogs %accesshash %userrolehash $processmarker $dumpcount
%coursedombuf %coursenumbuf %coursehombuf %coursedescrbuf %courseinstcodebuf %courseownerbuf %courseresdatacache
%userresdatacache %getsectioncache %domaindescription %domain_auth_def %domain_auth_arg_def
@@ -1023,9 +1023,9 @@
}
sub devalidate_cache_new {
- my ($cache,$name,$id) = @_;
+ my ($name,$id) = @_;
if (1) { &Apache::lonnet::logthis("deleting $name:$id"); }
- $cache->delete(&escape($name.':'.$id));
+ $memcache->delete(&escape($name.':'.$id));
}
my $to_remember=10;
@@ -1034,7 +1034,7 @@
my $kicks=0;
my $hits=0;
sub is_cached_new {
- my ($cache,$name,$id,$debug) = @_;
+ my ($name,$id,$debug) = @_;
$debug=0;
$id=&escape($name.':'.$id);
if (exists($remembered{$id})) {
@@ -1043,7 +1043,7 @@
$hits++;
return ($remembered{$id},1);
}
- my $value = $cache->get($id);
+ my $value = $memcache->get($id);
if (!(defined($value))) {
if ($debug) { &Apache::lonnet::logthis("getting $id is not defined"); }
return (undef,undef);
@@ -1058,7 +1058,7 @@
}
sub do_cache_new {
- my ($cache,$name,$id,$value,$time,$debug) = @_;
+ my ($name,$id,$value,$time,$debug) = @_;
$debug=0;
$id=&escape($name.':'.$id);
my $setvalue=$value;
@@ -1066,7 +1066,7 @@
$setvalue='__undef__';
}
if ($debug) { &Apache::lonnet::logthis("Setting $id to $value"); }
- $cache->set($id,$setvalue,300);
+ $memcache->set($id,$setvalue,300);
return $value;
}
@@ -4560,7 +4560,7 @@
# Everything is cached by the main uri, libraries are never directly cached
#
if (!defined($liburi)) {
- my ($result,$cached)=&is_cached_new($metacache,'meta',$uri);
+ my ($result,$cached)=&is_cached_new('meta',$uri);
if (defined($cached)) { return $result->{':'.$what}; }
}
{
@@ -4574,7 +4574,7 @@
$liburi=&declutter($liburi);
$filename=$liburi;
} else {
- &devalidate_cache_new($metacache,'meta',$uri);
+ &devalidate_cache_new('meta',$uri);
undef(%metaentry);
}
my %metathesekeys=();
@@ -4733,7 +4733,7 @@
$metaentry{':keys'}=join(',',keys %metathesekeys);
&metadata_generate_part0(\%metathesekeys,\%metaentry,$uri);
$metaentry{':allpossiblekeys'}=join(',',keys %metathesekeys);
- &do_cache_new($metacache,'meta',$uri,\%metaentry);
+ &do_cache_new('meta',$uri,\%metaentry);
# this is the end of "was not already recently cached
}
return $metaentry{':'.$what};
@@ -4797,7 +4797,7 @@
my $urlsymb=shift;
my $symb=&symbread($urlsymb);
if ($symb) {
- my ($result,$cached)=&is_cached(\%titlecache,$symb,'title',600);
+ my ($result,$cached)=&is_cached_new('title',$symb);
if (defined($cached)) {
return $result;
}
@@ -4812,7 +4812,7 @@
}
$title=~s/\&colon\;/\:/gs;
if ($title) {
- return &do_cache(\%titlecache,$symb,$title,'title');
+ return &do_cache_new('title',$symb,$title,600);
}
$urlsymb=$url;
}
@@ -5655,7 +5655,7 @@
#converted
# &logthis(sprintf("%-20s is %s",'%metacache',scalar(%metacache)));
&logthis(sprintf("%-20s is %s",'%homecache',length(&freeze(\%homecache))));
- &logthis(sprintf("%-20s is %s",'%titlecache',length(&freeze(\%titlecache))));
+# &logthis(sprintf("%-20s is %s",'%titlecache',length(&freeze(\%titlecache))));
&logthis(sprintf("%-20s is %s",'%courseresdatacache',length(&freeze(\%courseresdatacache))));
#1.1 only
&logthis(sprintf("%-20s is %s",'%userresdatacache',length(&freeze(\%userresdatacache))));
@@ -5810,7 +5810,7 @@
}
-$metacache=new Cache::Memcached({'servers'=>['127.0.0.1:11211']});
+$memcache=new Cache::Memcached({'servers'=>['127.0.0.1:11211']});
$processmarker='_'.time.'_'.$perlvar{'lonHostID'};
$dumpcount=0;