Cache::RemovalStrategy::LRU - LRU Removal Strategy for a Cache


Cache documentation Contained in the Cache distribution.

Index


Code Index:

NAME

Top

Cache::RemovalStrategy::LRU - LRU Removal Strategy for a Cache

DESCRIPTION

Top

Implements a Least Recently Used removal strategy for a Cache. When removing entries from the cache, the 'stalest' will be removed first.

METHODS

Top

See Cache::RemovalStrategy for details.

SEE ALSO

Top

Cache

AUTHOR

Top

 Chris Leishman <chris@leishman.org>
 Based on work by DeWitt Clinton <dewitt@unto.net>

COPYRIGHT

Top


Cache documentation Contained in the Cache distribution.
package Cache::RemovalStrategy::LRU;

require 5.006;
use strict;
use warnings;

use base qw(Cache::RemovalStrategy);
use fields qw();


sub new {
    my Cache::RemovalStrategy::LRU $self = shift;

    $self = fields::new($self) unless ref $self;
    $self->SUPER::new(@_);

    return $self;
}


sub remove_size {
    my Cache::RemovalStrategy::LRU $self = shift;
    my ($cache, $size) = @_;

    while ($size > 0) {
        my $removed = $cache->remove_stalest();
        defined $removed or last;
        $size -= $removed;
    }
}


1;
__END__