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