| 1 | package Zonemaster::Engine::Nameserver::Cache; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use v5.16.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use version; our $VERSION = version->declare("v1.0.4"); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Class::Accessor "antlers"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | our %object_cache; | |||||||||
| 11 | |||||||||||
| 12 | 1 | has 'data' => ( is => 'ro' ); | |||||||||
| 13 | 1 | has 'address' => ( is => 'ro' ); | |||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub get_cache_type { | ||||||||
|
Subroutine
get_cache_type: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 16 | 0 | my ( $class, $profile ) = @_; | |||||||||
| 17 | 0 | my $cache_type = 'LocalCache'; | |||||||||
| 18 | |||||||||||
| 19 | 0 | my %cache_config = %{ $profile->get( 'cache' ) }; | |||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | if ( exists $cache_config{'redis'} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | $cache_type = 'RedisCache'; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 0 | return $cache_type; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | sub get_cache_class { | ||||||||
|
Subroutine
get_cache_class: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 29 | 0 | my ( $class, $cache_type ) = @_; | |||||||||
| 30 | |||||||||||
| 31 | 0 | my $cache_class = "Zonemaster::Engine::Nameserver::Cache::$cache_type"; | |||||||||
| 32 | |||||||||||
| 33 | 0 | require ( "$cache_class.pm" =~ s{::}{/}gr ); | |||||||||
| 34 | 0 | $cache_class->import(); | |||||||||
| 35 | |||||||||||
| 36 | 0 | return $cache_class; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | sub empty_cache { | ||||||||
|
Subroutine
empty_cache: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 40 | 0 | %object_cache = (); | |||||||||
| 41 | |||||||||||
| 42 | 0 | return; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 1 | 1; | |||||||||
| 46 | |||||||||||
| 47 | =head1 NAME | ||||||||||
| 48 | |||||||||||
| 49 | Zonemaster::Engine::Nameserver::Cache - shared caches for nameserver objects | ||||||||||
| 50 | |||||||||||
| 51 | =head1 SYNOPSIS | ||||||||||
| 52 | |||||||||||
| 53 | This class should not be used directly. | ||||||||||
| 54 | |||||||||||
| 55 | =head1 ATTRIBUTES | ||||||||||
| 56 | |||||||||||
| 57 | =over | ||||||||||
| 58 | |||||||||||
| 59 | =item address | ||||||||||
| 60 | |||||||||||
| 61 | A L<Net::IP::XS> object holding the nameserver's address. | ||||||||||
| 62 | |||||||||||
| 63 | =item data | ||||||||||
| 64 | |||||||||||
| 65 | A reference to a hash holding the cache of sent queries. Not meant for external use. | ||||||||||
| 66 | |||||||||||
| 67 | =back | ||||||||||
| 68 | |||||||||||
| 69 | =head1 CLASS METHODS | ||||||||||
| 70 | |||||||||||
| 71 | =over | ||||||||||
| 72 | |||||||||||
| 73 | =item get_cache_type() | ||||||||||
| 74 | |||||||||||
| 75 | my $cache_type = get_cache_type( Zonemaster::Engine::Profile->effective ); | ||||||||||
| 76 | |||||||||||
| 77 | Get the cache type value from the profile, i.e. the name of the cache module to use. | ||||||||||
| 78 | |||||||||||
| 79 | Takes a L<Zonemaster::Engine::Profile> object. | ||||||||||
| 80 | |||||||||||
| 81 | Returns a string. | ||||||||||
| 82 | |||||||||||
| 83 | =item get_cache_class() | ||||||||||
| 84 | |||||||||||
| 85 | my $cache_class = get_cache_class( 'LocalCache' ); | ||||||||||
| 86 | |||||||||||
| 87 | Get the cache adapter class for the given database type. | ||||||||||
| 88 | |||||||||||
| 89 | Takes a string (cache database type). | ||||||||||
| 90 | |||||||||||
| 91 | Returns a string, or throws an exception if the cache adapter class cannot be loaded. | ||||||||||
| 92 | |||||||||||
| 93 | =item empty_cache() | ||||||||||
| 94 | |||||||||||
| 95 | Clear the cache. | ||||||||||
| 96 | |||||||||||
| 97 | =back | ||||||||||
| 98 | |||||||||||
| 99 | =cut | ||||||||||