line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::DB::Connector::Role::Cache; |
2
|
1
|
|
|
1
|
|
1004
|
use Mojo::Base -role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
3
|
1
|
|
|
1
|
|
342
|
use List::Util qw(pairs unpairs); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
4
|
1
|
|
|
1
|
|
417
|
use Mojo::Cache; |
|
1
|
|
|
|
|
352
|
|
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
|
1
|
|
26
|
use Mojo::Util (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
228
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
requires qw(_config _to_url new_connection); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has cache => sub { Mojo::Cache->new }; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub cached_connection { |
12
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
13
|
0
|
|
|
|
|
|
my %config = $self->_config(@_); |
14
|
0
|
|
|
|
|
|
my $mojo_url = $self->_to_url(%config); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# sort parameters so cached urls are the same |
17
|
|
|
|
|
|
|
$mojo_url->query( |
18
|
|
|
|
|
|
|
unpairs |
19
|
0
|
0
|
|
|
|
|
sort { $a->[0] cmp $b->[0] or $a->[1] cmp $b->[1] } |
20
|
0
|
|
|
|
|
|
pairs @{ $mojo_url->query->pairs } |
|
0
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
); |
22
|
0
|
|
0
|
|
|
|
my $cache_url = $mojo_url->userinfo(Mojo::Util::sha1_sum($mojo_url->userinfo // ''))->to_unsafe_string; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $connection; |
25
|
0
|
0
|
|
|
|
|
unless ($connection = $self->cache->get($cache_url)) { |
26
|
0
|
|
|
|
|
|
$connection = $self->new_connection(@_); |
27
|
0
|
|
|
|
|
|
$self->cache->set($cache_url => $connection); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
return $connection; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
__END__ |