blib/lib/PEF/Front/Cache/FastMmap.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 66 CC 4 SCAR 15.5
CC
4
Cov
0%
get_cache
12.0
BEGIN
6.0
set_cache
2.0
CRAP 4.7
1 package PEF::Front::Cache::FastMmap;
2 use strict;
3 use warnings;
4 use Cache::FastMmap;
5 use PEF::Front::Config;
6 use Time::Duration::Parse;
7 use Time::HiRes 'time';
8 use Data::Dumper;
9  
10 my $cache;
11  
12 BEGIN {
13 # empty grep means there's no config loaded - some statical
14 # analyzing tools can break
15 if (grep { /AppFrontConfig\.pm$/ } keys %INC) {
16 $cache = Cache::FastMmap->new(
17 share_file => cfg_cache_file,
18 cache_size => cfg_cache_size,
19 empty_on_exit => 0,
20 unlink_on_exit => 0,
21 expire_time => 0,
22 init_file => 1
23 ) or die "Can't create cache: $!";
24 }
25 }
26  
27 sub get_cache {
28 my $key = $_[0];
29 my $res = $cache->get($key);
30 if ($res) {
31 if ($res->[0] < time) {
32 $cache->remove($key);
33 return;
34 }
35 return $res->[1];
36 } else {
37 return;
38 }
39 }
40  
41 sub set_cache {
42 my ($key, $obj, $expires) = @_;
43 my $seconds = parse_duration($expires) || 60;
44 $cache->set($key, [$seconds + time, $obj]);
45 }
46  
47 sub remove_cache_key {
48 my $key = $_[0];
49 $cache->remove($key);
50 }
51  
52  
53 1;
54