2 # A class implimenting LRU sematics with hash look up
4 # Copyright (c) 2002 Dirk Koopman, Tobit Computer Co Ltd
8 # The structure of the objects stored are:-
10 # [next, prev, obj, callsign]
12 # The structure of the base is:-
14 # [next, prev, max objects, count ]
34 confess "LRU->newbase requires a name and maximal count" unless $name && $max;
35 return $pkg->SUPER::new({ }, $max, 0, $name);
40 my ($self, $call) = @_;
41 if (my $p = $self->obj->{$call}) {
42 dbg("LRU $self->[5] cache hit $call") if isdbg('lru');
51 my ($self, $call, $ref) = @_;
52 confess("need a call and a reference") unless defined $call && $ref;
53 my $p = $self->obj->{$call};
55 # update the reference and rechain it
56 dbg("LRU $self->[5] cache update $call") if isdbg('lru');
60 # delete one of the end of the chain if required
61 while ($self->[4] >= $self->[3] ) {
64 dbg("LRU $self->[5] cache LRUed out $call now $self->[4]/$self->[3]") if isdbg('lru');
69 dbg("LRU $self->[5] cache add $call now $self->[4]/$self->[3]") if isdbg('lru');
70 $p = $self->new($ref, $call);
72 $self->obj->{$call} = $p;
79 my ($self, $call) = @_;
80 my $q = $self->obj->{$call};
81 confess("$call is already removed") unless $q;
82 dbg("LRU $self->[5] cache remove $call now $self->[4]/$self->[3]") if isdbg('lru');
85 delete $self->obj->{$call};