/usr/share/perl5/Net/DRI/Cache.pm is in libnet-dri-perl 0.96-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | ## Domain Registry Interface, local global cache
##
## Copyright (c) 2005,2008,2009 Patrick Mevzek <netdri@dotandco.com>. All rights reserved.
##
## This file is part of Net::DRI
##
## Net::DRI is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## See the LICENSE file that comes with this distribution for more details.
#
#
#
#########################################################################################
package Net::DRI::Cache;
use strict;
use warnings;
use base qw(Class::Accessor::Chained::Fast);
__PACKAGE__->mk_accessors(qw/ttl/);
use Net::DRI::Util;
use Net::DRI::Exception;
our $VERSION=do { my @r=(q$Revision: 1.10 $=~/\d+/g); sprintf("%d".".%02d" x $#r, @r); };
=pod
=head1 NAME
Net::DRI::Cache - Local cache for Net::DRI
=head1 DESCRIPTION
Please see the README file for details.
=head1 SUPPORT
For now, support questions should be sent to:
E<lt>netdri@dotandco.comE<gt>
Please also see the SUPPORT file in the distribution.
=head1 SEE ALSO
E<lt>http://www.dotandco.com/services/software/Net-DRI/E<gt>
=head1 AUTHOR
Patrick Mevzek, E<lt>netdri@dotandco.comE<gt>
=head1 COPYRIGHT
Copyright (c) 2005,2008,2009 Patrick Mevzek <netdri@dotandco.com>.
All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
See the LICENSE file that comes with this distribution for more details.
=cut
####################################################################################################
sub new
{
my $c=shift;
my ($ttl)=@_;
my $self={
ttl => $ttl, ## if negative, never use cache
data => {},
};
bless($self,$c);
return $self;
}
sub set
{
my ($self,$regname,$type,$key,$data,$ttl)=@_;
Net::DRI::Exception::err_insufficient_parameters() unless Net::DRI::Util::all_valid($regname,$type,$key);
my $now=Net::DRI::Util::microtime();
$ttl=$self->{ttl} unless defined($ttl);
my $until=($ttl==0)? 0 : $now+1000000*$ttl;
my %c=(_on => $now,
_from => $regname,
_until => $until,
);
if ($data && (ref($data) eq 'HASH'))
{
while(my ($k,$v)=each(%$data))
{
$c{$k}=$v;
}
}
if ($self->{ttl} >= 0) ## we really store something
{
$self->{data}->{$type}={} unless exists($self->{data}->{$type});
## We store only the last version of a given key, so start from scratch
$self->{data}->{$type}->{$key}=\%c;
}
return \%c;
}
sub get
{
my ($self,$type,$key,$data,$from)=@_;
return if ($self->{ttl} < 0);
Net::DRI::Exception::err_insufficient_parameters() unless Net::DRI::Util::all_valid($type,$key);
($type,$key)=Net::DRI::Util::normalize_name($type,$key);
return unless exists($self->{data}->{$type});
return unless exists($self->{data}->{$type}->{$key});
my $c=$self->{data}->{$type}->{$key};
if ($c->{_until} > 0 && (Net::DRI::Util::microtime() > $c->{_until}))
{
delete($self->{data}->{$type}->{$key});
return;
}
return if (defined($from) && ($c->{_from} ne $from));
if (defined($data))
{
return $c->{$data} if exists($c->{$data});
} else
{
return $c;
}
return;
}
sub delete_expired
{
my $self=shift;
my $now=Net::DRI::Util::microtime();
my $c=$self->{data};
while(my ($type,$c1)=each(%$c))
{
while(my ($key,$c2)=each(%{$c1}))
{
delete($c->{$type}->{$key}) if ($c2->{_until} > 0 && ($now > $c2->{_until}));
}
}
}
sub delete
{
my $self=shift;
$self->{data}={};
}
####################################################################################################
1;
|