--- trunk/lib/WebPAC/Store.pm 2005/12/06 16:40:18 233 +++ trunk/lib/WebPAC/Store.pm 2006/09/25 18:58:43 710 @@ -10,23 +10,26 @@ =head1 NAME -WebPAC::Store - Store normalized data on disk +WebPAC::Store - Store WebPAC data on disk =head1 VERSION -Version 0.07 +Version 0.10 =cut -our $VERSION = '0.07'; +our $VERSION = '0.10'; =head1 SYNOPSIS -This module provides disk storage for normalised data. +This module provides disk storage for normalised data and lookups. -It is newest component of WebPAC, so it will change quite often or be in -flux. However, I will try to keep backward compatiblity by providing -multiple back-ends. +It is one of newer components of WebPAC, so it will change from time to +time. + +I will try to keep backward compatiblity by providing multiple back-ends, +but this can't be garanteed. In other words, don't delete your input +databases just yet :-) This has additional advantage. I can create single place to plugin other file formats which provide better performance for particular type of data. @@ -62,8 +65,8 @@ sub new { my $class = shift; - my $self = {@_}; - bless($self, $class); + my $self = {@_}; + bless($self, $class); my $log = $self->_get_logger(); @@ -128,7 +131,7 @@ Retrive from disk one data_structure records usually using field 000 as key - my $ds = $db->load_ds( id => 42, prefix => 'name' ); + my $ds = $db->load_ds( id => 42, prefix => 'name', database => 'ps' ); This function will also perform basic sanity checking on returned data and disable caching if data is corrupted (or changed since last @@ -137,6 +140,9 @@ C is used to differenciate different source input databases which are indexed in same database. +C if B argument which will override database name used when creating +C object (for simple retrival from multiple databases). + Returns hash or undef if cacheing is disabled or unavailable. =cut @@ -161,18 +167,14 @@ $log->logconfess("got hash, but without id") unless (defined($id)); $log->logconfess("got hash, but id [$id] isn't number") unless ($id =~ /^\d+$/); - my $database = $self->{database}; + my $database = $args->{database} || $self->{database}; my $prefix = $args->{prefix} || ''; $log->logconfess("can't find database name") unless ($database); - my $cache_file = "$cache_path/$database/$prefix#$id"; + my $cache_file = "$cache_path/$database/$prefix/$id"; $cache_file =~ s#//#/#go; -open(my $fh, '>>', '/tmp/foo'); -print $fh "LOAD $cache_path / $database / $prefix # $id ==> $cache_file\n"; -close($fh); - $log->debug("using cache_file $cache_file"); if (-r $cache_file) { @@ -230,9 +232,13 @@ my $prefix = $arg->{prefix} || ''; - my $cache_file = $self->{path} . "/$prefix#" . $arg->{id}; + my $cache_file = $self->{path} . '/' . $prefix . '/'; $cache_file =~ s#//#/#go; + mkpath($cache_file) unless (-d $cache_file); + + $cache_file .= $arg->{id}; + $log->debug("creating storable cache file $cache_file"); return store { @@ -242,6 +248,34 @@ } +=head2 save_lookup + + $db->save_lookup( $database, $input, $key, $lookup ); + +=cut + +sub save_lookup { + my $self = shift; + my ($database, $input, $key, $lookup) = @_; + + my $log = $self->_get_logger; + + my $path = $self->{'path'} . "/lookup/$input"; + + mkpath($path) unless (-d $path); + + $path .= "/$key"; + + if (store $lookup, $path) { + $log->info("saved lookup $path"); + } else { + $log->logwarn("can't store lookup $database/$input/$key in $path: $!"); + } + + +} + + =head1 AUTHOR Dobrica Pavlinusic, C<< >>