line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Model::Driver::Cache::Memcached; |
2
|
42
|
|
|
42
|
|
32371
|
use strict; |
|
42
|
|
|
|
|
229
|
|
|
42
|
|
|
|
|
1562
|
|
3
|
42
|
|
|
42
|
|
690
|
use warnings; |
|
42
|
|
|
|
|
80
|
|
|
42
|
|
|
|
|
1281
|
|
4
|
42
|
|
|
42
|
|
216
|
use base 'Data::Model::Driver::Cache'; |
|
42
|
|
|
|
|
65
|
|
|
42
|
|
|
|
|
28925
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub add_to_cache { |
8
|
0
|
|
|
0
|
0
|
|
my($self, $key, $data) = @_; |
9
|
|
|
|
|
|
|
|
10
|
0
|
|
|
|
|
|
my $ret = $self->{memcached}->add($key, $data); |
11
|
0
|
0
|
|
|
|
|
return if !defined $ret; |
12
|
0
|
|
|
|
|
|
return $ret; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub get_from_cache { |
16
|
0
|
|
|
0
|
0
|
|
my($self, $key) = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my $ret = $self->{memcached}->get($key); |
19
|
0
|
0
|
|
|
|
|
return if !defined $ret; |
20
|
0
|
|
|
|
|
|
return $ret; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub get_multi_from_cache { |
24
|
0
|
|
|
0
|
0
|
|
my($self, $keys) = @_; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my $ret = $self->{memcached}->get_multi($keys); |
27
|
0
|
0
|
|
|
|
|
return if !defined $ret; |
28
|
0
|
|
|
|
|
|
return $ret; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub remove_from_cache { |
32
|
0
|
|
|
0
|
0
|
|
my($self, $key) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $ret = $self->{memcached}->delete($key); |
35
|
0
|
0
|
|
|
|
|
return if !defined $ret; |
36
|
0
|
|
|
|
|
|
return $ret; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Data::Model::Driver::Cache::Memcached - Penetration cache is offered to the basic driver by memcached protocol |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 SYNOPSIS |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
package MyDB; |
48
|
|
|
|
|
|
|
use base 'Data::Model'; |
49
|
|
|
|
|
|
|
use Data::Model::Schema; |
50
|
|
|
|
|
|
|
use Data::Model::Driver::DBI; |
51
|
|
|
|
|
|
|
use Data::Model::Driver::Cache::Memcached; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $dbi_connect_options = {}; |
54
|
|
|
|
|
|
|
my $fallback_driver = Data::Model::Driver::DBI->new( |
55
|
|
|
|
|
|
|
dsn => 'dbi:mysql:host=localhost:database=test', |
56
|
|
|
|
|
|
|
username => 'user', |
57
|
|
|
|
|
|
|
password => 'password', |
58
|
|
|
|
|
|
|
connect_options => $dbi_connect_options, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $driver = Data::Model::Driver::Cache::Memcached->new( |
62
|
|
|
|
|
|
|
fallback => $fallback_driver, |
63
|
|
|
|
|
|
|
memcached => Cache::Memcached::Fast->new({ servers => [ { address => "localhost:11211" }, ], }), |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
base_driver $driver; |
67
|
|
|
|
|
|
|
install_model model_name => schema { |
68
|
|
|
|
|
|
|
.... |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 DESCRIPTION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Penetration cache is offered to the basic driver. |
74
|
|
|
|
|
|
|
Cash is stored in the memcached protocol server. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
When cash does not hit, it asks fallback driver. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SEE ALSO |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
L, |
81
|
|
|
|
|
|
|
L |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 AUTHOR |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Kazuhiro Osawa Eyappo shibuya plE |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 LICENSE |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
90
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |