| 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
|
|
692
|
use strict; |
|
|
6
|
|
|
|
|
7
|
|
|
|
6
|
|
|
|
|
185
|
|
|
19
|
6
|
|
|
6
|
|
20
|
use warnings; |
|
|
6
|
|
|
|
|
7
|
|
|
|
6
|
|
|
|
|
157
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
6
|
|
|
6
|
|
21
|
use base qw(Cache::RemovalStrategy); |
|
|
6
|
|
|
|
|
8
|
|
|
|
6
|
|
|
|
|
1845
|
|
|
22
|
6
|
|
|
6
|
|
23
|
use fields qw(); |
|
|
6
|
|
|
|
|
25
|
|
|
|
6
|
|
|
|
|
553
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
|
26
|
6
|
|
|
6
|
0
|
8
|
my Cache::RemovalStrategy::LRU $self = shift; |
|
27
|
|
|
|
|
|
|
|
|
28
|
6
|
50
|
|
|
|
27
|
$self = fields::new($self) unless ref $self; |
|
29
|
6
|
|
|
|
|
218
|
$self->SUPER::new(@_); |
|
30
|
|
|
|
|
|
|
|
|
31
|
6
|
|
|
|
|
11
|
return $self; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub remove_size { |
|
36
|
4
|
|
|
4
|
1
|
5
|
my Cache::RemovalStrategy::LRU $self = shift; |
|
37
|
4
|
|
|
|
|
4
|
my ($cache, $size) = @_; |
|
38
|
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
8
|
while ($size > 0) { |
|
40
|
4
|
|
|
|
|
10
|
my $removed = $cache->remove_stalest(); |
|
41
|
4
|
50
|
|
|
|
9
|
defined $removed or last; |
|
42
|
4
|
|
|
|
|
13
|
$size -= $removed; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
|
48
|
|
|
|
|
|
|
__END__ |