line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cache::BerkeleyDB; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
34324
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
6
|
1
|
|
|
1
|
|
6
|
use vars qw( @ISA ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
7
|
1
|
|
|
1
|
|
1020
|
use Cache::BaseCache; |
|
1
|
|
|
|
|
12480
|
|
|
1
|
|
|
|
|
56
|
|
8
|
1
|
|
|
1
|
|
10
|
use Cache::Cache; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
9
|
1
|
|
|
1
|
|
6
|
use Cache::CacheUtils qw ( Assert_Defined Static_Params ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
10
|
1
|
|
|
1
|
|
665
|
use Cache::BerkeleyDB_Backend; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@ISA = qw ( Cache::BaseCache ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $DEFAULT_CACHE_ROOT = "/tmp"; |
15
|
|
|
|
|
|
|
my $DEFAULT_NAMESPACE = 'Default'; |
16
|
|
|
|
|
|
|
my $DEFAULT_UMASK = 0002; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub Clear { |
19
|
|
|
|
|
|
|
my ($self,$cache_root) = _chkparm(@_); |
20
|
|
|
|
|
|
|
foreach my $ns ($self->_get_backend->get_namespaces) { |
21
|
|
|
|
|
|
|
_get_cache( $ns, $cache_root )->clear; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub Purge { |
26
|
|
|
|
|
|
|
my ($self,$cache_root) = _chkparm(@_); |
27
|
|
|
|
|
|
|
foreach my $ns ($self->_get_backend->get_namespaces) { |
28
|
|
|
|
|
|
|
_get_cache( $ns, $cache_root )->purge; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub Size { |
33
|
|
|
|
|
|
|
my ($self,$cache_root) = _chkparm(@_); |
34
|
|
|
|
|
|
|
my $size; |
35
|
|
|
|
|
|
|
foreach my $ns ($self->_get_backend->get_namespaces) { |
36
|
|
|
|
|
|
|
$size += _get_cache( $ns, $cache_root )->size; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
return $size; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# For methods callable as either instance or class methods. |
42
|
|
|
|
|
|
|
# This applies to Clear, Purge and Size. |
43
|
|
|
|
|
|
|
sub _chkparm { |
44
|
|
|
|
|
|
|
my ($self,$cache_root) = @_; |
45
|
|
|
|
|
|
|
unless (ref $self) { |
46
|
|
|
|
|
|
|
$cache_root = $self; |
47
|
|
|
|
|
|
|
$self = new Cache::BerkeleyDB; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
$cache_root ||= $self->{cache_root} || $DEFAULT_CACHE_ROOT; |
50
|
|
|
|
|
|
|
return ($self,$cache_root); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new { |
54
|
|
|
|
|
|
|
my ($class, $opt) = @_; |
55
|
|
|
|
|
|
|
$opt ||= {}; |
56
|
|
|
|
|
|
|
$opt->{cache_root} ||= $DEFAULT_CACHE_ROOT; |
57
|
|
|
|
|
|
|
$opt->{namespace} ||= $DEFAULT_NAMESPACE; |
58
|
|
|
|
|
|
|
$opt->{umask} ||= $DEFAULT_UMASK; |
59
|
|
|
|
|
|
|
$class = ref $class if ref $class; |
60
|
|
|
|
|
|
|
my $self = $class->SUPER::_new( $opt ); |
61
|
|
|
|
|
|
|
my $normal_umask = umask($opt->{umask}); |
62
|
|
|
|
|
|
|
mkdir $opt->{cache_root}, 0777 unless -d $opt->{cache_root}; |
63
|
|
|
|
|
|
|
$self->_set_backend( |
64
|
|
|
|
|
|
|
Cache::BerkeleyDB_Backend->new |
65
|
|
|
|
|
|
|
( $opt->{cache_root}, $opt->{namespace} ) |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
umask($normal_umask); |
68
|
|
|
|
|
|
|
$self->_complete_initialization; |
69
|
|
|
|
|
|
|
return $self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _get_cache { |
73
|
|
|
|
|
|
|
my ($namespace, $cache_root) = Static_Params(@_); |
74
|
|
|
|
|
|
|
Assert_Defined($namespace); |
75
|
|
|
|
|
|
|
$cache_root ||= $DEFAULT_CACHE_ROOT; |
76
|
|
|
|
|
|
|
return Cache::BerkeleyDB->new({ namespace => $namespace, |
77
|
|
|
|
|
|
|
cache_root=> $cache_root }); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub get_cache_root { |
81
|
|
|
|
|
|
|
my $self = shift; |
82
|
|
|
|
|
|
|
return $self->_get_backend->get_root; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub set_cache_root { |
86
|
|
|
|
|
|
|
my ($self,$cache_root) = @_; |
87
|
|
|
|
|
|
|
mkdir $cache_root, 0777 unless -d $cache_root; |
88
|
|
|
|
|
|
|
return $self->_get_backend->set_root($cache_root); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub size { |
92
|
|
|
|
|
|
|
my $self = shift; |
93
|
|
|
|
|
|
|
my $back = $self->_get_backend; |
94
|
|
|
|
|
|
|
my @keys = $back->get_keys; |
95
|
|
|
|
|
|
|
return 0 unless @keys; |
96
|
|
|
|
|
|
|
my $size; |
97
|
|
|
|
|
|
|
$size += $back->get_size($back->{_namespace},$_) for @keys; |
98
|
|
|
|
|
|
|
return $size; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |