File: Cache.pm

package info (click to toggle)
libzonemaster-perl 8.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 72,256 kB
  • sloc: perl: 16,941; makefile: 16
file content (99 lines) | stat: -rw-r--r-- 1,773 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package Zonemaster::Engine::Nameserver::Cache;

use v5.16.0;
use warnings;

use version; our $VERSION = version->declare("v1.0.4");

use Class::Accessor "antlers";

our %object_cache;

has 'data' => ( is => 'ro' );
has 'address' => ( is => 'ro' );

sub get_cache_type {
    my ( $class, $profile ) = @_;
    my $cache_type = 'LocalCache';

    my %cache_config = %{ $profile->get( 'cache' ) };

    if ( exists $cache_config{'redis'} ) {
        $cache_type = 'RedisCache';
    }

    return $cache_type;
}

sub get_cache_class {
    my ( $class, $cache_type ) = @_;

    my $cache_class = "Zonemaster::Engine::Nameserver::Cache::$cache_type";

    require ( "$cache_class.pm" =~ s{::}{/}gr );
    $cache_class->import();

    return $cache_class;
}

sub empty_cache {
    %object_cache = ();

    return;
}

1;

=head1 NAME

Zonemaster::Engine::Nameserver::Cache - shared caches for nameserver objects

=head1 SYNOPSIS

    This class should not be used directly.

=head1 ATTRIBUTES

=over

=item address

A L<Net::IP::XS> object holding the nameserver's address.

=item data

A reference to a hash holding the cache of sent queries. Not meant for external use.

=back

=head1 CLASS METHODS

=over

=item get_cache_type()

    my $cache_type = get_cache_type( Zonemaster::Engine::Profile->effective );

Get the cache type value from the profile, i.e. the name of the cache module to use.

Takes a L<Zonemaster::Engine::Profile> object.

Returns a string.

=item get_cache_class()

    my $cache_class = get_cache_class( 'LocalCache' );

Get the cache adapter class for the given database type.

Takes a string (cache database type).

Returns a string, or throws an exception if the cache adapter class cannot be loaded.

=item empty_cache()

Clear the cache.

=back

=cut