View on
Scott Walters > CHI-Driver-HandlerSocket-0.991 > CHI::Driver::HandlerSocket



Annotate this POD


New  1
Open  1
View/Report Bugs
Module Version: 0.991   Source  


CHI::Driver::HandlerSocket - Use DBI for cache storage, but access it using the Net::HandlerSocket API for MySQL


 use CHI;

 # Supply a DBI handle

 my $cache = CHI->new( driver => 'HandlerSocket', dbh => DBI->connect(...) );

ATTENTION: This module inherits tests from CHI but does not pass all of CHI's tests. It will not automatically install with cpanm or cpan because of this. Also, it won't pass all tests without database login information and cpanm skips the interactive prompts. You need to install this manually for now, I'm afraid.


This driver uses a MySQL database table to store the cache. It accesses it by way of the Net::HandlerSocket API and associated MySQL plug-in:

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 MySQL and HandlerSocket absolutely screams, avoiding most of the locking that normally happens and completing as many updates/queries as it can at once under the same lock. Avoiding parsing SQL is also a huge performance boost.



Host and port the MySQL server with the SocketHandler plugin is running on. The connection is TCP. Two connections are used, one for reading, one for writing, following the design of Net::HandlerSocket. The write port locks the table even for reads, reportedly. Default is localhost, 9998, and 9999.


The namespace you pass in will be appended to the table_prefix and used as a 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.


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 undef. Defaults to chi_.


The DBI handle used to communicate with the db.

You may pass this handle in one of three forms:

  • a regular DBI handle
  • a DBIx::Connector object

    XXXX doesn't work

  • 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 }

    XXXX doesn't work

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.



t/00load.t still referenced CHI::Handler::DBI and would fail if it you didn't have it installed. Fixed.

Tests will fail with a message about no tests run unless you run the install manuaully and give it valid DB login info. Todo: insert a dummy ok() in there.

Should have been specifying CHARSET=ASCII in the create statement to avoid, where utf-8 characters count triple or quadruple or whatever. Fixed, dubiously.

Huh, turns out that I was developing against CHI 0.36. Running tests with 0.42 shows me 31 failing tests.

Authors ^

CHI::Driver::HandlerSocket by Scott Walters ( for Plain Black Corp, CHI::Driver::HandlerSocket is based on CHI::Driver::DBI.

CHI::Driver::DBI Authors: Original version by Justin DeVuyst and Perrin Harkins. Currently maintained by Jonathan Swartz.


Copyright (c) Plain Black Corp 2011 Copyright (c) Scott Walters (scrottie) 2011 Copyright (c) Justin DeVuyst

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

syntax highlighting: