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
|
package Debian::PkgJs::Cache;
use strict;
use Exporter 'import';
our @EXPORT=('&CACHEDELAY');
use constant CACHEDELAY => 86400;
sub new {
my ( $class, %opts ) = @_;
my $self = bless {}, $class;
if ( $opts{clearcache} or !$opts{nocache} ) {
require Cache::FileCache;
$self->{_c} = new Cache::FileCache(
{
namespace => 'PkgJsDepends',
default_expires_in => $opts{cachedelay},
}
);
}
if ( $opts{clearcache} ) {
$self->{_c}->Clear();
exit 0;
}
elsif ( $self->{_c} ) {
$self->{_c}->purge;
}
return $self;
}
sub get {
my $self = shift;
return $self->_cmd( 'get', @_ );
}
sub set {
my $self = shift;
return $self->_cmd( 'set', @_ );
}
sub _cmd {
my $self = shift;
my $cmd = shift;
return $self->{_c} ? $self->{_c}->$cmd(@_) : undef;
}
1;
|