| 1 | package MojoX::Plugin::ManyCache; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use MojoX::Plugin::AnyCache; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | has 'pool'; | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | sub register { | ||||||||
|
Subroutine
register: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 9 | 1 | my ($self, $app, %args) = @_; | |||||||||
| 10 | |||||||||||
| 11 | 1 | my @cache_names = @{$args{names}}; | |||||||||
| 12 | 1 | my $config = $args{config}; | |||||||||
| 13 | |||||||||||
| 14 | 1 | $self->pool({}); | |||||||||
| 15 | |||||||||||
| 16 | 1 | foreach my $name (@cache_names) { | |||||||||
| 17 | 2 | ▶ | die "Missing cache configuration for cache '$name'" unless exists $config->{$name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 2 | $self->pool->{$name} = MojoX::Plugin::AnyCache->new( $config->{$name} ); | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | 1 | ▶ | $app->helper(cache => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||
| 22 | 1 | my (undef, $name) = @_; | |||||||||
| 23 | 1 | ▶ | die "Unknown cache '$name' " unless exists $self->pool->{$name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 1 | $self->pool->{$name} | |||||||||
| 25 | 1 | }); | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 2 | 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. | ||||||||||