line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package MooseX::WithCache::Backend::Cache::FileCache; |
3
|
1
|
|
|
1
|
|
1039
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
6519
|
use Moose::Util::TypeConstraints; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends 'MooseX::WithCache::Backend'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
class_type 'Cache::FileCache'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub _build_cache_type { |
11
|
1
|
|
|
1
|
|
37
|
return 'Cache::FileCache'; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
around _build_methods => sub { |
15
|
|
|
|
|
|
|
my ($next, $self) = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $methods = $next->($self); |
18
|
|
|
|
|
|
|
$methods->{cache_del} = sub { |
19
|
|
|
|
|
|
|
my ($self, $key) = @_; |
20
|
|
|
|
|
|
|
my $cache = $self->__get_cache(); |
21
|
|
|
|
|
|
|
if ($self->cache_disabled || ! $cache) { |
22
|
|
|
|
|
|
|
if (MooseX::WithCache::DEBUG()) { |
23
|
|
|
|
|
|
|
$self->cache_debug("cache_set: Cache disabled"); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
return (); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $keygen = $self->cache_key_generator; |
29
|
|
|
|
|
|
|
my $cache_key = $keygen ? $keygen->generate($key) : $key; |
30
|
|
|
|
|
|
|
if (MooseX::WithCache::DEBUG()) { |
31
|
|
|
|
|
|
|
$self->cache_debug( |
32
|
|
|
|
|
|
|
"cache_del: key =", |
33
|
|
|
|
|
|
|
($cache_key || '(null)'), |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
return $cache->remove($cache_key); |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
return $methods; |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
1
|
|
2586
|
no Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
44
|
1
|
|
|
1
|
|
230
|
no Moose::Util::TypeConstraints; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 NAME |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
MooseX::WithCache::Backend::Cache::FileCache - Cache::FileCache Backend |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 SYNOPSIS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
package MyObject; |
57
|
|
|
|
|
|
|
use MooseX::WithCache; |
58
|
|
|
|
|
|
|
with_cache( |
59
|
|
|
|
|
|
|
backend => 'Cache::FileCache' |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
package main; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $obj = MyObject->new( |
65
|
|
|
|
|
|
|
cache => Cache::FileCache->new({ ... }); |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$obj->cache_get($key); |
69
|
|
|
|
|
|
|
$obj->cache_set($key); |
70
|
|
|
|
|
|
|
$obj->cache_del($key); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# { |
73
|
|
|
|
|
|
|
# results => { |
74
|
|
|
|
|
|
|
# key1 => $cache_hit_value1, |
75
|
|
|
|
|
|
|
# key2 => $cache_hit_value2, |
76
|
|
|
|
|
|
|
# ... |
77
|
|
|
|
|
|
|
# }, |
78
|
|
|
|
|
|
|
# missing => [ 'key3', 'key4', 'key5' .... ] |
79
|
|
|
|
|
|
|
# } |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 METHODS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 build_cache_del_method |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 build_cache_get_method |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 build_cache_set_method |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 install_cache_attr |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |