| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package EntityModel::Cache::Memcached::Async; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Event-based memcached caching layer for EntityModel |
|
3
|
|
|
|
|
|
|
use EntityModel::Class { |
|
4
|
1
|
|
|
|
|
11
|
_isa => [qw{EntityModel::Cache}], |
|
5
|
|
|
|
|
|
|
mc => 'Net::Async::Memcached', |
|
6
|
1
|
|
|
1
|
|
1675
|
}; |
|
|
1
|
|
|
|
|
80163
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
EntityModel::Cache::Memcached::Async - support for memcached via L |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
version 0.001 |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
EntityModel->new->add_cache('Memcached::Async' => { |
|
21
|
|
|
|
|
|
|
servers => [qw(127.0.0.1:11211)], |
|
22
|
|
|
|
|
|
|
}); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 METHODS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 get |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Get value for the given key. |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub get { |
|
35
|
|
|
|
|
|
|
my $self = shift; |
|
36
|
|
|
|
|
|
|
my $k = shift; |
|
37
|
|
|
|
|
|
|
$self->mc->get($k, @_); |
|
38
|
|
|
|
|
|
|
return $self; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 remove |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Remove an entry from the cache. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub remove { |
|
48
|
|
|
|
|
|
|
my $self = shift; |
|
49
|
|
|
|
|
|
|
my $k = shift; |
|
50
|
|
|
|
|
|
|
# FIXME Proper delete support |
|
51
|
|
|
|
|
|
|
$self->mc->delete($k => '', @_); |
|
52
|
|
|
|
|
|
|
return $self; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 incr |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Increment a cache value. Should be atomic, currently isn't. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub incr { |
|
62
|
|
|
|
|
|
|
my $self = shift; |
|
63
|
|
|
|
|
|
|
my $k = shift; |
|
64
|
|
|
|
|
|
|
my %args = @_; |
|
65
|
|
|
|
|
|
|
# FIXME Atomic incr support |
|
66
|
|
|
|
|
|
|
$self->mc->get( |
|
67
|
|
|
|
|
|
|
$k, |
|
68
|
|
|
|
|
|
|
on_complete => sub { |
|
69
|
|
|
|
|
|
|
my $mc = shift; |
|
70
|
|
|
|
|
|
|
my $v = shift; |
|
71
|
|
|
|
|
|
|
++$v; |
|
72
|
|
|
|
|
|
|
$mc->set( |
|
73
|
|
|
|
|
|
|
$k => $v, |
|
74
|
|
|
|
|
|
|
%args |
|
75
|
|
|
|
|
|
|
); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
); |
|
78
|
|
|
|
|
|
|
return $self; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 decr |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Decrement a cache value. Should be atomic, isn't yet. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub decr { |
|
88
|
|
|
|
|
|
|
my $self = shift; |
|
89
|
|
|
|
|
|
|
my $k = shift; |
|
90
|
|
|
|
|
|
|
my %args = @_; |
|
91
|
|
|
|
|
|
|
# FIXME Atomic decr support |
|
92
|
|
|
|
|
|
|
$self->mc->get( |
|
93
|
|
|
|
|
|
|
$k, |
|
94
|
|
|
|
|
|
|
on_complete => sub { |
|
95
|
|
|
|
|
|
|
my $mc = shift; |
|
96
|
|
|
|
|
|
|
my $v = shift; |
|
97
|
|
|
|
|
|
|
--$v; |
|
98
|
|
|
|
|
|
|
$mc->set( |
|
99
|
|
|
|
|
|
|
$k => $v, |
|
100
|
|
|
|
|
|
|
%args |
|
101
|
|
|
|
|
|
|
); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
); |
|
104
|
|
|
|
|
|
|
return $self; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 set |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub set { |
|
112
|
|
|
|
|
|
|
my $self = shift; |
|
113
|
|
|
|
|
|
|
my $k = shift; |
|
114
|
|
|
|
|
|
|
my $v = shift; |
|
115
|
|
|
|
|
|
|
$self->mc->set($k => $v, @_); |
|
116
|
|
|
|
|
|
|
return $self; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 atomic |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Atomic access to a cache value. Not implemented. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub atomic { |
|
126
|
|
|
|
|
|
|
my $self = shift; |
|
127
|
|
|
|
|
|
|
die 'Not yet implemented'; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |