line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::Plugin::MemcachedFast; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Dancer::Plugin::MemcachedFast::VERSION = '0.130500'; |
4
|
|
|
|
|
|
|
} |
5
|
3
|
|
|
3
|
|
661658
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
109
|
|
6
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
77
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
2424
|
use Dancer::Plugin; |
|
3
|
|
|
|
|
113995
|
|
|
3
|
|
|
|
|
289
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
3454
|
use Cache::Memcached::Fast; |
|
3
|
|
|
|
|
11395
|
|
|
3
|
|
|
|
|
4260
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $default_timeout = 3600; |
13
|
|
|
|
|
|
|
my $ok_to_compress = 0; |
14
|
|
|
|
|
|
|
my $cache = do { |
15
|
|
|
|
|
|
|
my $config = plugin_setting; |
16
|
|
|
|
|
|
|
$config->{servers} = [ $ENV{HAVE_TEST_MEMCACHED_SERVER_LOCALHOST} ] |
17
|
|
|
|
|
|
|
if exists $ENV{HAVE_TEST_MEMCACHED_SERVER_LOCALHOST}; |
18
|
|
|
|
|
|
|
$default_timeout = delete $config->{default_timeout} |
19
|
|
|
|
|
|
|
if exists $config->{default_timeout}; |
20
|
|
|
|
|
|
|
$ok_to_compress = |
21
|
|
|
|
|
|
|
( defined $config->{compress_threshold} |
22
|
|
|
|
|
|
|
and int($config->{compress_threshold}) > 1 |
23
|
|
|
|
|
|
|
and defined $config->{compress_method}); |
24
|
|
|
|
|
|
|
Cache::Memcached::Fast->new($config); |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
register memcached_compress => sub { |
28
|
0
|
0
|
|
0
|
|
|
unless ($ok_to_compress) { |
29
|
0
|
|
|
|
|
|
warn |
30
|
|
|
|
|
|
|
"Cannot compress. Check the 'compress_threshold' and 'compress_method' configuration options"; |
31
|
0
|
|
|
|
|
|
return; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
$cache->compress( |
34
|
0
|
|
|
|
|
|
!!$_[ 0 ] |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
register memcached_get_or_set => sub { |
39
|
|
|
|
|
|
|
$cache->get($_[ 0 ]) |
40
|
0
|
0
|
0
|
0
|
|
|
or do { |
41
|
0
|
|
|
|
|
|
my $ret; |
42
|
0
|
0
|
|
|
|
|
$cache->set($_[ 0 ], |
43
|
|
|
|
|
|
|
$ret = ref $_[ 1 ] eq 'CODE' ? $_[ 1 ]->() : $_[ 1 ]); |
44
|
0
|
|
|
|
|
|
$ret; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
or $_[ 1 ]; |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
register memcached_get => sub { |
50
|
0
|
0
|
0
|
0
|
|
|
return $cache->get($_[ 0 ]) if $#_ == 0 and !ref $_[ 0 ]; |
51
|
0
|
0
|
|
|
|
|
$cache->get_multi(map {ref $_ and ref $_ eq 'ARRAY' ? @$_ : $_} @_); |
|
0
|
0
|
|
|
|
|
|
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
register memcached_gets => sub { |
55
|
0
|
0
|
0
|
0
|
|
|
return $cache->gets($_[ 0 ]) if $#_ == 0 and !ref $_[ 0 ]; |
56
|
0
|
0
|
|
|
|
|
$cache->gets_multi(map {ref $_ and ref $_ eq 'ARRAY' ? @$_ : $_} @_); |
|
0
|
0
|
|
|
|
|
|
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
register memcached_set => sub { |
60
|
0
|
0
|
|
0
|
|
|
return $cache->set( |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$_[ 0 ], |
62
|
|
|
|
|
|
|
ref $_[ 1 ] eq 'CODE' ? $_[ 1 ]->() : $_[ 1 ], |
63
|
|
|
|
|
|
|
defined $_[ 2 ] ? $_[ 2 ] : $default_timeout |
64
|
|
|
|
|
|
|
) if ref $_[ 0 ] ne 'ARRAY'; |
65
|
0
|
0
|
|
|
|
|
$cache->set_multi( |
|
|
0
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
map {[ |
67
|
|
|
|
|
|
|
$_->[ 0 ], |
68
|
|
|
|
|
|
|
ref $_->[ 1 ] eq 'CODE' ? $_->[ 1 ]->() : $_->[ 1 ], |
69
|
|
|
|
|
|
|
defined $_->[ 2 ] ? $_->[ 2 ] : $default_timeout |
70
|
|
|
|
|
|
|
] |
71
|
0
|
|
|
|
|
|
} grep {ref $_ eq 'ARRAY'} @_ |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
register memcached_add => sub { |
76
|
0
|
0
|
|
0
|
|
|
return $cache->add( |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$_[ 0 ], |
78
|
|
|
|
|
|
|
ref $_[ 1 ] eq 'CODE' ? $_[ 1 ]->() : $_[ 1 ], |
79
|
|
|
|
|
|
|
defined $_[ 2 ] ? $_[ 2 ] : $default_timeout |
80
|
|
|
|
|
|
|
) if ref $_[ 0 ] ne 'ARRAY'; |
81
|
0
|
0
|
|
|
|
|
$cache->add_multi( |
|
|
0
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
map {[ |
83
|
|
|
|
|
|
|
$_->[ 0 ], |
84
|
|
|
|
|
|
|
ref $_->[ 1 ] eq 'CODE' ? $_->[ 1 ]->() : $_->[ 1 ], |
85
|
|
|
|
|
|
|
defined $_->[ 2 ] ? $_->[ 2 ] : $default_timeout |
86
|
|
|
|
|
|
|
] |
87
|
0
|
|
|
|
|
|
} grep {ref $_ eq 'ARRAY'} @_ |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
}; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
register memcached_replace => sub { |
92
|
0
|
0
|
|
0
|
|
|
return $cache->replace( |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$_[ 0 ], |
94
|
|
|
|
|
|
|
ref $_[ 1 ] eq 'CODE' ? $_[ 1 ]->() : $_[ 1 ], |
95
|
|
|
|
|
|
|
defined $_[ 2 ] ? $_[ 2 ] : $default_timeout |
96
|
|
|
|
|
|
|
) if ref $_[ 0 ] ne 'ARRAY'; |
97
|
0
|
0
|
|
|
|
|
$cache->replace_multi( |
|
|
0
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
map {[ |
99
|
|
|
|
|
|
|
$_->[ 0 ], |
100
|
|
|
|
|
|
|
ref $_->[ 1 ] eq 'CODE' ? $_->[ 1 ]->() : $_->[ 1 ], |
101
|
|
|
|
|
|
|
defined $_->[ 2 ] ? $_->[ 2 ] : $default_timeout |
102
|
|
|
|
|
|
|
] |
103
|
0
|
|
|
|
|
|
} grep {ref $_ eq 'ARRAY'} @_ |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
}; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
register memcached_delete => sub { |
108
|
0
|
0
|
0
|
0
|
|
|
return $cache->delete($_[ 0 ]) |
109
|
|
|
|
|
|
|
if $#_ == 0 and !ref $_[ 0 ]; |
110
|
0
|
0
|
0
|
|
|
|
$cache->delete_multi( |
111
|
0
|
|
|
|
|
|
map {(ref $_ and ref $_ eq 'ARRAY') ? @$_ : $_} @_ |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
}; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
register memcached_append => sub { |
116
|
0
|
0
|
0
|
0
|
|
|
return $cache->append(@_) |
|
|
|
0
|
|
|
|
|
117
|
|
|
|
|
|
|
if ($#_ == 1 and !ref $_[ 0 ] and !ref $_[ 1 ]); |
118
|
0
|
|
|
|
|
|
$cache->append_multi( |
119
|
0
|
|
|
|
|
|
grep {ref $_ eq 'ARRAY'} @_ |
120
|
|
|
|
|
|
|
); |
121
|
|
|
|
|
|
|
}; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
register memcached_prepend => sub { |
124
|
0
|
0
|
0
|
0
|
|
|
return $cache->prepend(@_) |
|
|
|
0
|
|
|
|
|
125
|
|
|
|
|
|
|
if ($#_ == 1 and !ref $_[ 0 ] and !ref $_[ 1 ]); |
126
|
0
|
|
|
|
|
|
$cache->prepend_multi( |
127
|
0
|
|
|
|
|
|
grep {ref $_ eq 'ARRAY'} @_ |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
}; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
register memcached_incr => sub { |
132
|
0
|
|
|
|
|
|
return $cache->incr(@_) |
133
|
0
|
0
|
0
|
0
|
|
|
if ($#_ <= 2 and scalar grep {!ref $_} @_); |
134
|
0
|
|
|
|
|
|
$cache->incr_multi( |
135
|
0
|
|
|
|
|
|
grep {ref $_ eq 'ARRAY'} @_ |
136
|
|
|
|
|
|
|
); |
137
|
|
|
|
|
|
|
}; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
register memcached_decr => sub { |
140
|
0
|
|
|
|
|
|
return $cache->decr(@_) |
141
|
0
|
0
|
0
|
0
|
|
|
if ($#_ <= 2 and scalar grep {!ref $_} @_); |
142
|
0
|
|
|
|
|
|
$cache->decr_multi( |
143
|
0
|
|
|
|
|
|
grep {ref $_ eq 'ARRAY'} @_ |
144
|
|
|
|
|
|
|
); |
145
|
|
|
|
|
|
|
}; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
register memcached_flush_all => sub { |
148
|
0
|
|
|
0
|
|
|
$cache->flush_all( |
149
|
|
|
|
|
|
|
@_); |
150
|
|
|
|
|
|
|
}; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
register memcached_nowait_push => sub { |
153
|
0
|
|
|
0
|
|
|
$cache->nowait_push; |
154
|
|
|
|
|
|
|
}; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
register memcached_server_versions => sub { |
157
|
0
|
|
|
0
|
|
|
$cache->server_versions; |
158
|
|
|
|
|
|
|
}; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
register memcached_disconnect_all => sub { |
161
|
0
|
|
|
0
|
|
|
$cache->disconnect_all; |
162
|
|
|
|
|
|
|
}; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
register memcached_namespace => sub { |
165
|
0
|
|
|
0
|
|
|
$cache->namespace( |
166
|
|
|
|
|
|
|
$_[ 0 ] |
167
|
|
|
|
|
|
|
); |
168
|
|
|
|
|
|
|
}; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
register_plugin; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
__END__ |