line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dezi::Cache; |
2
|
2
|
|
|
2
|
|
10
|
use Moose; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
14
|
|
3
|
|
|
|
|
|
|
with 'Dezi::Role'; |
4
|
2
|
|
|
2
|
|
12794
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
152
|
|
5
|
2
|
|
|
2
|
|
858
|
use namespace::autoclean; |
|
2
|
|
|
|
|
8485
|
|
|
2
|
|
|
|
|
56
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.014'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'cache' => ( is => 'rw' ); |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
191
|
no Moose; # since we have our own 'has' method |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=pod |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Dezi::Cache - simple in-memory cache class |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Dezi::Cache; |
22
|
|
|
|
|
|
|
my $cache = Dezi::Cache->new; |
23
|
|
|
|
|
|
|
$cache->add( foo => 'bar' ); |
24
|
|
|
|
|
|
|
$cache->has( 'foo' ); # returns true |
25
|
|
|
|
|
|
|
$cache->get( 'foo' ); # returns 'bar' |
26
|
|
|
|
|
|
|
$cache->delete( 'foo' ); # removes 'foo' from cache and returns 'bar' |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Dezi::Cache is a simple in-memory caching class. It's basically |
31
|
|
|
|
|
|
|
just a Perl hash, but implemented as a class so that you can subclass it |
32
|
|
|
|
|
|
|
and use different storage (e.g. Cache::* modules). |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 METHODS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
See Dezi::Class. Only new or overridden methods are documented here. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 BUILD |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Initialize the cache. Called internally by new(). You should not need to |
43
|
|
|
|
|
|
|
call this yourself. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub BUILD { |
48
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
49
|
0
|
|
0
|
|
|
|
$self->{cache} ||= {}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 cache([ I<hash_ref> ]) |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Get/set the internal in-memory cache. The default is just a hash ref. |
55
|
|
|
|
|
|
|
Subclasses are encouraged to implement their own storage. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 has( I<key> ) |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Does I<key> exist in cache. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub has { |
64
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
65
|
0
|
|
|
|
|
|
my $key = shift; |
66
|
0
|
0
|
|
|
|
|
defined($key) or croak "key required"; |
67
|
0
|
|
|
|
|
|
return exists $self->{cache}->{$key}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 get( I<key> ) |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Returns value for I<key>. Returns undef if has( I<key> ) is false. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub get { |
77
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
78
|
0
|
|
|
|
|
|
my $key = shift; |
79
|
0
|
0
|
|
|
|
|
defined($key) or croak "key required"; |
80
|
0
|
0
|
|
|
|
|
return exists $self->{cache}->{$key} ? $self->{cache}->{$key} : undef; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 delete( I<key> ) |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Delete I<key> from cache. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub delete { |
90
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
91
|
0
|
|
|
|
|
|
my $key = shift; |
92
|
0
|
0
|
|
|
|
|
defined($key) or croak "key required"; |
93
|
0
|
|
|
|
|
|
delete $self->{cache}->{$key}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 add( I<key> => I<value> ) |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Add I<key> to cache with value I<value>. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub add { |
103
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
104
|
0
|
|
|
|
|
|
my $key = shift; |
105
|
0
|
|
|
|
|
|
my $val = shift; |
106
|
0
|
0
|
|
|
|
|
defined($key) or croak "key required"; |
107
|
0
|
|
|
|
|
|
$self->{cache}->{$key} = $val; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Peter Karman, E<lt>perl@peknet.comE<gt> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 BUGS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-swish-prog at rt.cpan.org>, or through |
121
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dezi-App>. |
122
|
|
|
|
|
|
|
I will be notified, and then you'll |
123
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SUPPORT |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
perldoc Dezi |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
You can also look for information at: |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=over 4 |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * Mailing list |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L<http://lists.swish-e.org/listinfo/users> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dezi-App> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Dezi-App> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * CPAN Ratings |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Dezi-App> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * Search CPAN |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/Dezi-App/> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Copyright 2008-2009 by Peter Karman |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
163
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SEE ALSO |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L<http://swish-e.org/> |