GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
CHI::Driver::DBI(3) User Contributed Perl Documentation CHI::Driver::DBI(3)

CHI::Driver::DBI - Use DBI for cache storage

version 1.27

    use CHI;
    
    # Supply a DBI handle
    #
    my $cache = CHI->new( driver => 'DBI', dbh => DBI->connect(...) );
    
    # or a DBIx::Connector
    #
    my $cache = CHI->new( driver => 'DBI', dbh => DBIx::Connector->new(...) );
    
    # or code that generates a DBI handle
    #
    my $cache = CHI->new( driver => 'DBI', dbh => sub { ...; return $dbh } );

This driver uses a database table to store the cache. The newest versions of MySQL and SQLite work are known to work. Other RDBMSes should work.

Why cache things in a database? Isn't the database what people are trying to avoid with caches? This is often true, but a simple primary key lookup is extremely fast in many databases and this provides a shared cache that can be used when less reliable storage like memcached is not appropriate. Also, the speed of simple lookups on MySQL when accessed over a local socket is very hard to beat. DBI is fast.

Each namespace requires a table like this:

    CREATE TABLE chi_<namespace> (
       `key` VARCHAR(...),
       `value` TEXT,
       PRIMARY KEY (`key`)
    )

The size of the key column depends on how large you want keys to be and may be limited by the maximum size of an indexed column in your database.

The driver will try to create an appropriate table for you if you pass "create_table" to the constructor.

create_table
Boolean. If true, attempt to create the database table if it does not already exist. Defaults to false.
namespace
The namespace you pass in will be appended to the "table_prefix" to form the table name. That means that if you don't specify a namespace or table_prefix the cache will be stored in a table called "chi_Default".
table_prefix
This is the prefix that is used when building a table name. If you want to just use the namespace as a literal table name, set this to the empty string. Defaults to "chi_".
dbh
The main, or rw, DBI handle used to communicate with the db. If a dbh_ro handle is defined then this handle will only be used for writing.

You may pass this handle, and dbh_ro below, in one of three forms:

  • a regular DBI handle
  • a DBIx::Connector object
  • a code reference that will be called each time and is expected to return a DBI handle, e.g.

        sub { My::Rose::DB->new->dbh }
        

The last two options are valuable if your CHI object is going to live for enough time that a single DBI handle might time out, etc.

dbh_ro
The optional DBI handle used for read-only operations. This is to support master/slave RDBMS setups.

Original version by Justin DeVuyst and Perrin Harkins. Currently maintained by Jonathan Swartz.

This software is copyright (c) 2011 by Justin DeVuyst.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

2014-09-11 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.