line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package App::TinyMVC::Cache; |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
59
|
|
6
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
85
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.01_2'; |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
2144
|
use Cache::Memcached; |
|
2
|
|
|
|
|
301124
|
|
|
2
|
|
|
|
|
1039
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
0
|
|
my($class) = @_; |
14
|
0
|
|
|
|
|
|
my $self = bless({}, $class); |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
my $memd = new Cache::Memcached { |
17
|
|
|
|
|
|
|
'servers' => [ "127.0.0.1:11211" ], |
18
|
|
|
|
|
|
|
'debug' => 0, |
19
|
|
|
|
|
|
|
'compress_threshold' => 10_000, |
20
|
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
$self->{'memd'} = $memd; |
23
|
0
|
|
|
|
|
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub set { |
27
|
0
|
|
|
0
|
0
|
|
my($self,$tinymvc,$prefix,$key,$value,$expire) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
unless ($tinymvc->{'config'}->{'cache'}->{'enabled'}) { |
30
|
0
|
|
|
|
|
|
$tinymvc->log('cache','cache disabled in configuration'); |
31
|
0
|
|
|
|
|
|
return undef; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
0
|
|
|
|
if (defined($tinymvc->{'context'}->{'query_string'}->{'cache'}) and $tinymvc->{'context'}->{'query_string'}->{'cache'} eq 'no') { |
35
|
0
|
|
|
|
|
|
$tinymvc->log('cache',"Skipped set by query_string! ".'desporto_stats:'.$prefix.'::'.$key); |
36
|
0
|
|
|
|
|
|
return; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
unless ($expire) { |
40
|
0
|
|
|
|
|
|
$expire = $tinymvc->{'config'}->{'controllers'}->{$tinymvc->controller}->{$tinymvc->action}->{'expire'}; |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
|
$tinymvc->log('cache',"set: ".'desporto_stats:'.$prefix.'::'.$key." Expire: $expire"); |
43
|
0
|
|
|
|
|
|
$self->{'memd'}->set('desporto_stats:'.$prefix.'::'.$key, $value, $expire); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get { |
47
|
0
|
|
|
0
|
0
|
|
my($self,$tinymvc,$prefix,$key) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
unless ($tinymvc->{'config'}->{'cache'}->{'enabled'}) { |
50
|
0
|
|
|
|
|
|
$tinymvc->log('cache','cache disabled in configuration'); |
51
|
0
|
|
|
|
|
|
return undef; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
0
|
|
|
|
if (defined($tinymvc->{'context'}->{'query_string'}->{'cache'}) and ($tinymvc->{'context'}->{'query_string'}->{'cache'} eq 'no' or $tinymvc->{'context'}->{'query_string'}->{'cache'} eq 'reset') ) { |
|
|
|
0
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$tinymvc->log('cache',"Skipped get by query_string! ".'desporto_stats:'.$prefix.'::'.$key); |
56
|
0
|
|
|
|
|
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $res; |
60
|
0
|
0
|
|
|
|
|
if ($res = $self->{'memd'}->get('desporto_stats:'.$prefix.'::'.$key)) { |
61
|
0
|
|
|
|
|
|
$tinymvc->log('cache',"Hit! ".'desporto_stats:'.$prefix.'::'.$key); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
0
|
|
|
|
|
|
$tinymvc->log('cache',"Miss! ".'desporto_stats:'.$prefix.'::'.$key); |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
$res; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |