line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Terse::Plugin::CHI; |
2
|
1
|
|
|
1
|
|
69246
|
use 5.006; use strict; use warnings; |
|
1
|
|
|
1
|
|
3
|
|
|
1
|
|
|
1
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
59
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
1
|
|
|
1
|
|
6
|
use base 'Terse::Plugin'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
558
|
|
5
|
1
|
|
|
1
|
|
115867
|
use CHI; use JSON; |
|
1
|
|
|
1
|
|
89631
|
|
|
1
|
|
|
|
|
33
|
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub build_plugin { |
8
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
9
|
|
|
|
|
|
|
$self->cache = CHI->new( |
10
|
|
|
|
|
|
|
driver => 'Memory', |
11
|
|
|
|
|
|
|
global => 1, |
12
|
0
|
0
|
|
|
|
|
($self->chi ? %{ $self->chi } : ()) |
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub set { |
17
|
0
|
|
|
0
|
0
|
|
my ($self, $content, $timeout, $unique) = @_; |
18
|
0
|
|
0
|
|
|
|
$unique ||= [caller(1)]->[3]; |
19
|
0
|
0
|
|
|
|
|
$self->cache->set( $unique, $content->response->serialize(), (defined $timeout ? $timeout : ()) ); |
20
|
0
|
|
|
|
|
|
return $content; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub get { |
24
|
0
|
|
|
0
|
0
|
|
my ($self, $t, $unique) = @_; |
25
|
0
|
|
0
|
|
|
|
$unique ||= [caller(1)]->[3]; |
26
|
0
|
|
|
|
|
|
my $c = $self->cache->get($unique); |
27
|
0
|
|
|
|
|
|
$t->graft('response', $c); |
28
|
0
|
|
|
|
|
|
return $t; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
__END__ |