File Coverage

blib/lib/Mail/BIMI/CacheBackend/FastMmap.pm
Criterion Covered Total %
statement 31 31 100.0
branch 2 2 100.0
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 44 44 100.0


line stmt bran cond sub pod time code
1             package Mail::BIMI::CacheBackend::FastMmap;
2             # ABSTRACT: Cache handling
3             our $VERSION = '3.20210512'; # VERSION
4 29     29   455 use 5.20.0;
  29         140  
5 29     29   236 use Moose;
  29         103  
  29         652  
6 29     29   230475 use Mail::BIMI::Prelude;
  29         97  
  29         311  
7 29     29   30279 use Cache::FastMmap;
  29         166265  
  29         8558  
8              
9             with 'Mail::BIMI::Role::CacheBackend';
10             has _cache_fastmmap => ( is => 'rw', lazy => 1, builder => '_build_cache_fastmmap' );
11              
12              
13 9     9   27 sub _build_cache_fastmmap($self) {
  9         24  
  9         21  
14 9         278 my $cache_filename = $self->parent->bimi_object->options->cache_fastmmap_share_file;
15 9 100       661 my $init_file = -e $cache_filename ? 0 : 1;
16 9         106 my $cache = Cache::FastMmap->new( share_file => $cache_filename, serializer => 'sereal', init_file => $init_file, unlink_on_exit => 0 );
17 9         15149 return $cache;
18             }
19              
20              
21 9     9 1 32 sub get_from_cache($self) {
  9         29  
  9         31  
22 9         278 return $self->_cache_fastmmap->get($self->_cache_hash);
23             }
24              
25              
26 2     2 1 12 sub put_to_cache($self,$data) {
  2         14  
  2         9  
  2         4  
27 2         69 $self->_cache_fastmmap->set($self->_cache_hash,$data);
28             }
29              
30              
31 2     2 1 11 sub delete_cache($self) {
  2         11  
  2         5  
32 2         64 $self->_cache_fastmmap->remove($self->_cache_hash);
33             }
34              
35             1;
36              
37             __END__
38              
39             =pod
40              
41             =encoding UTF-8
42              
43             =head1 NAME
44              
45             Mail::BIMI::CacheBackend::FastMmap - Cache handling
46              
47             =head1 VERSION
48              
49             version 3.20210512
50              
51             =head1 DESCRIPTION
52              
53             Cache worker role for Cache::FastMmap backend
54              
55             =head1 ATTRIBUTES
56              
57             These values are derived from lookups and verifications made based upon the input values, it is however possible to override these with other values should you wish to, for example, validate a record before it is published in DNS, or validate an Indicator which is only available locally
58              
59             =head2 parent
60              
61             is=ro required
62              
63             Parent class for cacheing
64              
65             =head1 CONSUMES
66              
67             =over 4
68              
69             =item * L<Mail::BIMI::Role::CacheBackend>
70              
71             =back
72              
73             =head1 EXTENDS
74              
75             =over 4
76              
77             =item * L<Moose::Object>
78              
79             =back
80              
81             =head1 METHODS
82              
83             =head2 I<get_from_cache()>
84              
85             Retrieve this class data from cache
86              
87             =head2 I<put_to_cache($data)>
88              
89             Put this classes data into the cache
90              
91             =head2 I<delete_cache>
92              
93             Delete the cache entry for this class
94              
95             =head1 REQUIRES
96              
97             =over 4
98              
99             =item * L<Cache::FastMmap|Cache::FastMmap>
100              
101             =item * L<Mail::BIMI::Prelude|Mail::BIMI::Prelude>
102              
103             =item * L<Moose|Moose>
104              
105             =back
106              
107             =head1 AUTHOR
108              
109             Marc Bradshaw <marc@marcbradshaw.net>
110              
111             =head1 COPYRIGHT AND LICENSE
112              
113             This software is copyright (c) 2020 by Marc Bradshaw.
114              
115             This is free software; you can redistribute it and/or modify it under
116             the same terms as the Perl 5 programming language system itself.
117              
118             =cut