line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Cache::RemovalStrategy::LRU - LRU Removal Strategy for a Cache |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 DESCRIPTION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Implements a Least Recently Used removal strategy for a Cache. When removing |
8
|
|
|
|
|
|
|
entries from the cache, the 'stalest' will be removed first. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 METHODS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
See Cache::RemovalStrategy for details. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
package Cache::RemovalStrategy::LRU; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
require 5.006; |
18
|
6
|
|
|
6
|
|
947
|
use strict; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
271
|
|
19
|
6
|
|
|
6
|
|
35
|
use warnings; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
430
|
|
20
|
|
|
|
|
|
|
|
21
|
6
|
|
|
6
|
|
34
|
use base qw(Cache::RemovalStrategy); |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
4483
|
|
22
|
6
|
|
|
6
|
|
38
|
use fields qw(); |
|
6
|
|
|
|
|
30
|
|
|
6
|
|
|
|
|
1169
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
26
|
6
|
|
|
6
|
0
|
13
|
my Cache::RemovalStrategy::LRU $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
6
|
50
|
|
|
|
53
|
$self = fields::new($self) unless ref $self; |
29
|
6
|
|
|
|
|
320
|
$self->SUPER::new(@_); |
30
|
|
|
|
|
|
|
|
31
|
6
|
|
|
|
|
17
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub remove_size { |
36
|
4
|
|
|
4
|
1
|
10
|
my Cache::RemovalStrategy::LRU $self = shift; |
37
|
4
|
|
|
|
|
49
|
my ($cache, $size) = @_; |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
12
|
while ($size > 0) { |
40
|
4
|
|
|
|
|
17
|
my $removed = $cache->remove_stalest(); |
41
|
4
|
50
|
|
|
|
46
|
defined $removed or last; |
42
|
4
|
|
|
|
|
18
|
$size -= $removed; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
__END__ |