line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cache::Funky::Storage::Memcached; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22414
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
5
|
1
|
|
|
1
|
|
6
|
use base qw/Cache::Funky::Storage/; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
849
|
|
6
|
1
|
|
|
1
|
|
5452
|
use Cache::Memcached; |
|
1
|
|
|
|
|
173997
|
|
|
1
|
|
|
|
|
233
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
12
|
0
|
|
|
|
|
|
my $args = shift; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
my $s = {}; |
15
|
0
|
|
|
|
|
|
$s->{memcached} = Cache::Memcached->new($args); |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
return bless $s, $class; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub set { |
21
|
0
|
|
|
0
|
1
|
|
my $s = shift; |
22
|
0
|
|
|
|
|
|
my $key = shift; |
23
|
0
|
|
|
|
|
|
my $value = shift; |
24
|
0
|
|
|
|
|
|
my $id = shift; |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
$key = $id ? $key . ':' . $id : $key; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$s->{memcached}->set( $key, $value ); |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
return; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub get { |
34
|
0
|
|
|
0
|
1
|
|
my $s = shift; |
35
|
0
|
|
|
|
|
|
my $key = shift; |
36
|
0
|
|
|
|
|
|
my $id = shift; |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
$key = $id ? $key . ':' . $id : $key; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
return $s->{memcached}->get($key); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub delete { |
45
|
0
|
|
|
0
|
1
|
|
my $s = shift; |
46
|
0
|
|
|
|
|
|
my $key = shift; |
47
|
0
|
|
|
|
|
|
my $id = shift; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
$key = $id ? $key . ':' . $id : $key; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$s->{memcached}->delete($key); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 NAME |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Cache::Funky::Storage::Memcached - Cache::Funky Memcached Storage. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 DESCRIPTION |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Memcached Storage for L |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 SYNOPSIS |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
package MyCache; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
use strict; |
69
|
|
|
|
|
|
|
use Cache::Memcached; |
70
|
|
|
|
|
|
|
use base qw/Cache::Funky/; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__PACKAGE__->setup('Storage::Memcached' => { servers => [ '127.0.0.1:12345' ] }); |
73
|
|
|
|
|
|
|
__PACKAGE__->register( 'foo', sub { time } ); |
74
|
|
|
|
|
|
|
__PACKAGE__->register( 'boo', sub { shift . '_' . `date` } ); # * date: $id + _Tue May 1 21:53:36 JST 2007 |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
run.pl |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
#!/usr/bin/perl |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
use strict; |
83
|
|
|
|
|
|
|
use MyCache; |
84
|
|
|
|
|
|
|
use Perl6::Say; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
say ( MyCache->foo() ); |
87
|
|
|
|
|
|
|
sleep(3); |
88
|
|
|
|
|
|
|
say ( MyCache->foo() ); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
MyCache->delete('foo'); |
91
|
|
|
|
|
|
|
say ( MyCache->foo() ); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
say ( MyCache->boo('id1') ); |
94
|
|
|
|
|
|
|
say ( MyCache->boo('id2') ); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sleep 10; |
97
|
|
|
|
|
|
|
say ( MyCache->boo('id1') ); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# only remove id1 |
100
|
|
|
|
|
|
|
MyCache->delete('boo', 'id1'); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
say ( MyCache->boo('id1') ); |
103
|
|
|
|
|
|
|
say ( MyCache->boo('id2') ); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
MyCache->deletes([qw/foo boo/]); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 METHOD |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 new |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 set |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 get |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 delete |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 SEE ALSO |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
L |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 AUTHOR |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Tomohiro Teranishi |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Copyright (c) Tomohiro Teranishi, All rights reserved. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |