--- trunk/lib/WebPAC/Store.pm 2005/12/05 17:47:51 217 +++ trunk/lib/WebPAC/Store.pm 2005/12/05 17:48:00 218 @@ -14,11 +14,11 @@ =head1 VERSION -Version 0.05 +Version 0.06 =cut -our $VERSION = '0.05'; +our $VERSION = '0.06'; =head1 SYNOPSIS @@ -56,6 +56,8 @@ If called with C it will not disable caching if called without write permission (but will die on C). +Mandatory parametar C is used as subdirectory in database directory. + =cut sub new { @@ -63,6 +65,12 @@ my $self = {@_}; bless($self, $class); + my $log = $self->_get_logger(); + + foreach my $p (qw/path database/) { + $log->logconfess("need $p") unless ($self->{$p}); + } + $self->path( $self->{'path'} ); $self ? return $self : return undef; @@ -120,12 +128,15 @@ Retrive from disk one data_structure records usually using field 000 as key - my $ds = $db->load_ds( id => 42, database => 'name' ); + my $ds = $db->load_ds( id => 42, prefix => 'name' ); This function will also perform basic sanity checking on returned data and disable caching if data is corrupted (or changed since last update). +C is used to differenciate different source input databases +which are indexed in same database. + Returns hash or undef if cacheing is disabled or unavailable. =cut @@ -148,14 +159,19 @@ my $id = $args->{id}; $log->logconfess("got hash, but without id") unless (defined($id)); - $log->logconfess("got hash, but id isn't number") unless ($id =~ /^\d+$/); + $log->logconfess("got hash, but id [$id] isn't number") unless ($id =~ /^\d+$/); - my $database = $args->{database} || $self->{database}; + my $database = $self->{database}; + my $prefix = $args->{prefix} || ''; $log->logconfess("can't find database name") unless ($database); - my $cache_file = "$cache_path/$database#$id"; - $cache_file =~ s#//#/#g; + my $cache_file = "$cache_path/$prefix/$database#$id"; + $cache_file =~ s#//#/#go; + +open(my $fh, '>>', '/tmp/foo'); +print $fh "$cache_file\n"; +close($fh); $log->debug("using cache_file $cache_file"); @@ -184,7 +200,7 @@ $db->save_ds( id => $ds->{000}->[0], - database => 'name', + prefix => 'name', ds => $ds, ); @@ -209,10 +225,13 @@ $log->logconfess("need $f") unless ($arg->{$f}); } - my $database = $arg->{database} || $self->{database}; + my $database = $self->{database}; $log->logconfess("can't find database name") unless ($database); - my $cache_file = $self->{path} . '/' . $database . '#' . $arg->{id}; + my $prefix = $arg->{prefix} || ''; + + my $cache_file = $self->{path} . "/$prefix/$database#" . $arg->{id}; + $cache_file =~ s#//#/#go; $log->debug("creating storable cache file $cache_file");