line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenPlugin::Cache::File; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: File.pm,v 1.15 2003/04/03 01:51:24 andreychek Exp $ |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
4894
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
136
|
|
6
|
2
|
|
|
2
|
|
2248
|
use OpenPlugin::Cache(); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
45
|
|
7
|
2
|
|
|
2
|
|
13
|
use base qw( OpenPlugin::Cache ); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
221
|
|
8
|
2
|
|
|
2
|
|
1928
|
use Cache::FileCache(); |
|
2
|
|
|
|
|
193766
|
|
|
2
|
|
|
|
|
1229
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$OpenPlugin::Cache::File::VERSION = sprintf("%d.%02d", q$Revision: 1.15 $ =~ /(\d+)\.(\d+)/); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub init { |
13
|
2
|
|
|
2
|
0
|
5
|
my ( $self, $args ) = @_; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
|
|
38
|
$self->state( 'cache', Cache::FileCache->new() ); |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
13
|
return $self; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub fetch { |
21
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $id ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
5
|
$self->OP->log->info( "Retrieving ($id) from the cache." ); |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
37
|
return $self->state->{cache}->get( $id ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub save { |
30
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $data, $params ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
1
|
50
|
|
|
|
5
|
return undef unless $data; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
33
|
|
|
13
|
$params->{id} ||= OpenPlugin::Utility->generate_rand_id(); |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
33
|
|
|
14
|
$params->{expires} ||= OpenPlugin::Utility->expire_calc( |
37
|
|
|
|
|
|
|
$self->OP->config->{plugin}{cache}{expires} ); |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
7
|
$self->state->{cache}->set( $params->{id}, |
40
|
|
|
|
|
|
|
$data, |
41
|
|
|
|
|
|
|
$params->{expires} |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
3354
|
$self->OP->log->info( "Saved ($params->{id}) to the cache." ); |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
509
|
return $params->{id}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub delete { |
51
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $id ) = @_; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
5
|
$self->OP->log->info( "Deleting ($id) from the cache." ); |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
45
|
return $self->state->{cache}->remove( $id ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |