--- trunk/lib/WebPAC/Normalize.pm 2005/07/17 10:42:23 15 +++ trunk/lib/WebPAC/Normalize.pm 2005/07/17 14:53:37 18 @@ -3,7 +3,6 @@ use warnings; use strict; use Data::Dumper; -use Storable; =head1 NAME @@ -79,16 +78,13 @@ return length($_); }, ... }, - cache_data_structure => './cache/ds/', + db => $webpac_db_obj, lookup_regex => $lookup->regex, ); Parametar C defines user supplied snippets of perl code which can be use with C notation. -Optional parameter C defines path to directory -in which cache file for C call will be created. - Recommended parametar C is used to enable parsing of lookups in structures. @@ -99,51 +95,9 @@ my $self = {@_}; bless($self, $class); - $self->setup_cache_dir( $self->{'cache_data_structure'} ); - $self ? return $self : return undef; } -=head2 setup_cache_dir - -Check if specified cache directory exist, and if not, disable caching. - - $setup_cache_dir('./cache/ds/'); - -If you pass false or zero value to this function, it will disable -cacheing. - -=cut - -sub setup_cache_dir { - my $self = shift; - - my $dir = shift; - - my $log = $self->_get_logger(); - - if ($dir) { - my $msg; - if (! -e $dir) { - $msg = "doesn't exist"; - } elsif (! -d $dir) { - $msg = "is not directory"; - } elsif (! -w $dir) { - $msg = "not writable"; - } - - if ($msg) { - undef $self->{'cache_data_structure'}; - $log->warn("cache_data_structure $dir $msg, disabling..."); - } else { - $log->debug("using cache dir $dir"); - } - } else { - $log->debug("disabling cache"); - undef $self->{'cache_data_structure'}; - } -} - =head2 data_structure @@ -172,35 +126,9 @@ my $cache_file; - if (my $cache_path = $self->{'cache_data_structure'}) { - my $id = $rec->{'000'}; - $id = $rec->{'000'}->[0] if ($id =~ m/^ARRAY/o); - unless (defined($id)) { - $log->warn("Can't use cache_data_structure on records without unique identifier in field 000"); - undef $self->{'cache_data_structure'}; - } else { - $cache_file = "$cache_path/$id"; - if (-r $cache_file) { - my $ds_ref = retrieve($cache_file); - if ($ds_ref) { - $log->debug("cache hit: $cache_file"); - my $ok = 1; - foreach my $f (qw(current_filename headline)) { - if ($ds_ref->{$f}) { - $self->{$f} = $ds_ref->{$f}; - } else { - $ok = 0; - } - }; - if ($ok && $ds_ref->{'ds'}) { - return @{ $ds_ref->{'ds'} }; - } else { - $log->warn("cache_data_structure $cache_path corrupt. Use rm $cache_path/* to re-create it on next run!"); - undef $self->{'cache_data_structure'}; - } - } - } - } + if ($self->{'db'}) { + my @ds = $self->{'db'}->get_ds($rec); + return @ds if (@ds); } undef $self->{'currnet_filename'}; @@ -308,14 +236,11 @@ } - if ($cache_file) { - store { - ds => \@ds, - current_filename => $self->{'current_filename'}, - headline => $self->{'headline'}, - }, $cache_file; - $log->debug("created storable cache file $cache_file"); - } + $self->{'db'}->put_gs( + ds => \@ds, + current_filename => $self->{'current_filename'}, + headline => $self->{'headline'}, + ) if ($self->{'db'}); return @ds;