return( $self->error( "Table cache file \"$tables_cache_file\" does not have write permission: ", $tables_cache_file->error ) );
}
else
{
return( $self->error( "Although table cache file \"$tables_cache_file\" is writable, I am unable to write to it: ", $tables_cache_file->error ) );
}
}
1;
# NOTE: POD
__END__
=encoding utf-8
=head1 NAME
DB::Object::Cache::Tables - Table Cache
=head1 SYNOPSIS
my $cache = DB::Object::Cache::Tables->new({
timeout => 86400,
# This is automatically set
# cache_file => '/some/dir/sql_tables.json',
});
$dbh->cache_tables( $cache_tables );
$tables = $dbh->tables_info;
my $cache =
{
host => $host,
driver => $driver,
port => $port,
database => $database,
tables => $tables,
};
if( !defined( $cache->set( $cache ) ) )
{
warn( "Unable to write to tables cache: ", $cache->error, "\n" );
}
# Returning an array reference of tables hash reference definition
$all = $cache_tables->get({
host => $self->host,
driver => $self->driver,
port => $self->port,
database => $db,
}) || do
=head1 VERSION
v0.100.5
=head1 DESCRIPTION
This is a simple way to maintain a cache of database tables in a session. When a connection object is created, it will issue a query to get the list of all tables and views in the database and pass it to L<DB::Object::Cache::Tables>, and save its object. It is then used later several times such as when instantiating table objects.
=head1 METHODS
=head2 init
Possible parameters:
=over 4
=item I<cache_dir>
An absolute path to a directory that will contain the json cache file. Beware that if you run your script from the web, this directory must be writable by the http server user.
=item I<cache_file>
Alternatively to I<cache_dir>, you can provide an absolute path to the json cache file.
=item I<timeout>
An amount of time in second until the cache file becomes obsolete.
=back
=head2 cache
Returns the hash reference structure of the cache
=head2 cache_dir
Set or get the cache dir.
When set, this will also set the cache file calling L</"cache_file">
=head2 cache_file
Set or get the cache file.
When set, this will store the cache file modification time to check later if it has become obsolete and load its json data into the L</"cache">
=head2 get
Given an hash reference of parameters, this will return an array reference of table hash reference.
Parameters are:
=over 4
=item I<host>
=item I<driver>
=item I<port>
=item I<database>
=back
=head2 read
Given a full path to a json cache file, this will read the file and return its data as a hash reference.
If an error occurs while reading the json cache file, it will issue a warning using B<warn> and return an empty hash reference.
=head2 set
Provided with an hash reference of parameters, this will add it to the cache data and write it to the file.
Parameters are:
=over 4
=item I<host>
=item I<driver>
=item I<port>
=item I<database>
=item I<tables>
An array reference of hash reference containing table definition as returned by L<DB::Object::table_info>
=back
=head2 timeout
Set/get the cache file timeout.
If the current unix timestamp minus the cache file timestamp is higher than the timeout, the cache file has expired.
=head2 updated
Set/get the cache file last modified unix timestamp
=head2 write
Provided with a cache data, which is a hash reference and optionally the full path to the cache file, and B<write> will write the hash data as a json to the cache file.
If no cache file is provided as a second argument, it will use the default one set up when the object was instantiated.
It returns the size of the cache file or return undef and set the B<error>
=head1 COPYRIGHT
Copyright (c) 2000-2019 DEGUEST Pte. Ltd.
=head1 SEE ALSO
L<DB::Object>
=head1 AUTHOR
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
=head1 COPYRIGHT & LICENSE
Copyright (c) 2018-2021 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated
files under the same terms as Perl itself.
=cut
Keyboard Shortcuts
Global
s
Focus search bar
?
Bring up this help dialog
GitHub
gp
Go to pull requests
gi
go to github issues (only if github is preferred repository)