Sman::Man::Cache::FileCache - Cache converted manpages in a Cache::FileCache


Sman documentation Contained in the Sman distribution.

Index


Code Index:

NAME

Top

Sman::Man::Cache::FileCache - Cache converted manpages in a Cache::FileCache

SYNOPSIS

Top

  # this module is intended for internal use by sman-update
  my $cache = new Sman::Man::Cache::FileCache();
  $cache->set("/usr/man/man3/ls.3", "some stuff");

  # ..later...

  my $ret = $cache->get("/usr/man/man3/ps.3");
  # $ret will be undef if data not found.

DESCRIPTION

Top

Uses a Cache::FileCache to store raw data for use by Sman::Man::Convert.

AUTHOR

Top

Josh Rabinowitz <joshr>

SEE ALSO

Top

sman-update, Sman::Man::Convert, sman.conf, Sman::Man::Cache


Sman documentation Contained in the Sman distribution.

package Sman::Man::Cache::FileCache;

#$Id: FileCache.pm,v 1.7 2006/02/27 02:07:19 joshr Exp $

use Cache::FileCache;

use base 'Sman::Man::Cache';
use fields qw( filecache );

# pass a dir to store the cache data in
sub new {
   my $class = shift;
	my $dir = shift;
   my $self = fields::new($class);

   $self->SUPER::new();                # init base fields 

	if (defined($dir)) {
		my %hash = ( 'namespace' => 'sman', 'default_expires_in' => "1 month" );
		$^W=0;	# avoid pseudo-hash warnings on perl 5.8.0
		$self->{filecache} = new Cache::FileCache( \%hash );
	}
	return $self;
}

sub get {
	my $self = shift;
	my $key = shift;
	my $val;
	#local $^W = 0;	# hide 'pseudo-hashes are deprecated' warnings in perl 5.8.0
	no warnings;	# hide 'pseudo-hashes are deprecated' warnings in perl 5.8.0
	if (defined($self->{filecache}) && ($val = $self->{filecache}->get($key) ) ) {
		return $val;
	}
	return undef;
}
sub set {
	my $self = shift;
	my $key = shift;	
	# we handle rawdata right from $_[0]. Why not?
	#local $^W = 0;	# hide 'pseudo-hashes are deprecated' warnings in perl 5.8.0
	no warnings;	# hide 'pseudo-hashes are deprecated' warnings in perl 5.8.0
	$self->{filecache}->set($key, $_[0]) if ($self->{filecache});
} 
sub Clear {
	my $self = shift;
	my $cache = $self->{filecache};
	defined($cache) && ($cache->Clear());
}

1;