X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXUser.pm;h=afc70cb0e08516f0331b19264782528950e8d823;hb=9c415b19aaaf0497e9cc074f3df56f16fe414e82;hp=690a8ae4d99b2aaf1fe97c52fa82d7cb05de114f;hpb=dbf7523a9b228dbdf1d03109afde351b8b194fab;p=spider.git diff --git a/perl/DXUser.pm b/perl/DXUser.pm index 690a8ae4..afc70cb0 100644 --- a/perl/DXUser.pm +++ b/perl/DXUser.pm @@ -15,6 +15,7 @@ use Fcntl; use IO::File; use DXDebug; use DXUtil; +use LRU; use strict; @@ -24,13 +25,14 @@ $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)) $main::build += $VERSION; $main::branch += $BRANCH; -use vars qw(%u $dbm $filename %valid $lastoperinterval $lasttime); +use vars qw(%u $dbm $filename %valid $lastoperinterval $lasttime $lru $lrusize); %u = (); $dbm = undef; $filename = undef; $lastoperinterval = 60*24*60*60; $lasttime = 0; +$lrusize = 2000; # hash of valid elements and a simple prompt %valid = ( @@ -84,26 +86,29 @@ $lasttime = 0; build => '1,Build', ); -no strict; +#no strict; sub AUTOLOAD { my $self = shift; + no strict; my $name = $AUTOLOAD; return if $name =~ /::DESTROY$/; - $name =~ s/.*:://o; + $name =~ s/^.*:://o; confess "Non-existant field '$AUTOLOAD'" if !$valid{$name}; # this clever line of code creates a subroutine which takes over from autoload # from OO Perl - Conway - *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ; - if (@_) { - $self->{$name} = shift; - } - return $self->{$name}; + *$AUTOLOAD = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}}; + &$AUTOLOAD($self, @_); +# *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ; +# if (@_) { +# $self->{$name} = shift; +# } +# return $self->{$name}; } -use strict; +#use strict; # # initialise the system @@ -121,6 +126,7 @@ sub init } $filename = $fn; + $lru = LRU->newbase("DXUser", $lrusize); } sub del_file @@ -182,8 +188,16 @@ sub get my $pkg = shift; my $call = uc shift; my $data; + + # is it in the LRU cache? + my $ref = $lru->get($call); + return $ref if $ref; + + # search for it unless ($dbm->get($call, $data)) { - return decode($data); + $ref = decode($data); + $lru->put($call, $ref); + return $ref; } return undef; } @@ -233,7 +247,9 @@ sub put $dbm->del($call); delete $self->{annok} if $self->{annok}; delete $self->{dxok} if $self->{dxok}; - $dbm->put($call, $self->encode); + $lru->put($call, $self); + my $ref = $self->encode; + $dbm->put($call, $ref); } # @@ -277,6 +293,7 @@ sub del # for ($dbm->get_dup($call)) { # $dbm->del_dup($call, $_); # } + $lru->remove($call); $dbm->del($call); }