line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cache::Ref::FIFO; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
1085
|
$Cache::Ref::FIFO::AUTHORITY = 'cpan:NUFFIN'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
1
|
|
|
1
|
|
18
|
$Cache::Ref::FIFO::VERSION = '0.05'; # TRIAL |
7
|
|
|
|
|
|
|
} |
8
|
1
|
|
|
1
|
|
458
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use namespace::autoclean; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
extends qw(Cache::Ref); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with qw( |
15
|
|
|
|
|
|
|
Cache::Ref::Role::API |
16
|
|
|
|
|
|
|
Cache::Ref::Role::Index |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has size => ( |
20
|
|
|
|
|
|
|
isa => "Int", |
21
|
|
|
|
|
|
|
is => "ro", |
22
|
|
|
|
|
|
|
required => 1, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has _fifo => ( |
26
|
|
|
|
|
|
|
isa => "ArrayRef", |
27
|
|
|
|
|
|
|
is => "ro", |
28
|
|
|
|
|
|
|
lazy => 1, |
29
|
|
|
|
|
|
|
default => sub { [] }, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub clear { |
33
|
|
|
|
|
|
|
my $self = shift; |
34
|
|
|
|
|
|
|
$self->_index_clear; |
35
|
|
|
|
|
|
|
@{ $self->_fifo } = (); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub hit { } |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub remove { |
41
|
|
|
|
|
|
|
my ( $self, @keys ) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->_index_delete(@keys); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my %keys; @keys{@keys} = (); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $f = $self->_fifo; |
48
|
|
|
|
|
|
|
@$f = grep { not exists $keys{$_} } @$f; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub get { |
54
|
|
|
|
|
|
|
my ( $self, @keys ) = @_; |
55
|
|
|
|
|
|
|
$self->_index_get(@keys); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub set { |
59
|
|
|
|
|
|
|
my ( $self, $key, $value ) = @_; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
unless ( defined $self->_index_get($key) ) { |
62
|
|
|
|
|
|
|
if ( $self->_index_size >= $self->size ) { |
63
|
|
|
|
|
|
|
$self->expire( 1 + $self->_index_size - $self->size ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
push @{ $self->_fifo }, $key; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$self->_index_set($key, $value); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub expire { |
72
|
|
|
|
|
|
|
my ( $self, $how_many ) = @_; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$self->_index_delete( splice @{ $self->_fifo }, 0, $how_many || 1 ); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# ex: set sw=4 et: |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__PACKAGE__; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |
87
|
|
|
|
|
|
|
=pod |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=encoding utf-8 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 NAME |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Cache::Ref::FIFO |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 AUTHOR |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Yuval Kogman |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Yuval Kogman. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
104
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|