line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Plugin::ManyCache; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
2382
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
15
|
|
4
|
2
|
|
|
2
|
|
1908
|
use MojoX::Plugin::AnyCache; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
23
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has 'pool'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub register { |
9
|
1
|
|
|
1
|
1
|
1472
|
my ($self, $app, %args) = @_; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
2
|
my @cache_names = @{$args{names}}; |
|
1
|
|
|
|
|
3
|
|
12
|
1
|
|
|
|
|
2
|
my $config = $args{config}; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
30
|
$self->pool({}); |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
12
|
foreach my $name (@cache_names) { |
17
|
2
|
50
|
|
|
|
36
|
die "Missing cache configuration for cache '$name'" unless exists $config->{$name}; |
18
|
2
|
|
|
|
|
10
|
$self->pool->{$name} = MojoX::Plugin::AnyCache->new( $config->{$name} ); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$app->helper(cache => sub { |
22
|
1
|
|
|
1
|
|
957
|
my (undef, $name) = @_; |
23
|
1
|
50
|
|
|
|
255
|
die "Unknown cache '$name' " unless exists $self->pool->{$name}; |
24
|
1
|
|
|
|
|
33
|
$self->pool->{$name} |
25
|
1
|
|
|
|
|
33
|
}); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
1; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=encoding utf8 |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 NAME |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
MojoX::Plugin::ManyCache - Multi-Cache plugin with blocking and non-blocking support |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 SYNOPSIS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$app->plugin('MojoX::Plugin::ManyCache', |
39
|
|
|
|
|
|
|
names => qw[ cache_one cache_two ], |
40
|
|
|
|
|
|
|
config => { |
41
|
|
|
|
|
|
|
cache_one => { |
42
|
|
|
|
|
|
|
backend => 'MojoX::Plugin::AnyCache::Backend::Redis', |
43
|
|
|
|
|
|
|
server => '127.0.0.1:6379', |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
cache_two => { |
46
|
|
|
|
|
|
|
backend => 'MojoX::Plugin::AnyCache::Backend::Redis', |
47
|
|
|
|
|
|
|
server => '10.1.1.1:6379', |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$app->cache('cache_one')->set('key', 'value')l |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
MojoX::Plugin::ManyCache provides an interface to multiple AnyCache instances. |