DB::Object::Cache::Tables - Table Cache
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
v0.100.3
This is a simple given 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 DB::Object::Cache::Tables, and save its object. It is then used later several times such as when instantiating table objects.
Possible parameters:
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.
Alternatively to cache_dir, you can provide an absolute path to the json cache file.
An amount of time in second until the cache file becomes obsolete.
Returns the hash reference structure of the cache
Set or get the cache dir.
When set, this will also set the cache file calling "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 "cache"
Given an hash reference of parameters, this will return an array reference of table hash reference.
Parameters are:
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 warn and return an empty hash reference.
Provided with an hash reference of parameters, this will add it to the cache data and write it to the file.
An array reference of hash reference containing table definition as returned by DB::Object::table_info
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.
Set/get the cache file last modified unix timestamp
Provided with a cache data, which is a hash reference and optionally the full path to the cache file, and 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 error
Copyright (c) 2000-2019 DEGUEST Pte. Ltd.
DB::Object
Jacques Deguest <jack@deguest.jp>
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.
To install DB::Object, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DB::Object
CPAN shell
perl -MCPAN -e shell install DB::Object
For more information on module installation, please visit the detailed CPAN module installation guide.