NAME

MemcacheDBI - Queue memcache calls when in a dbh transaction

SYNOPSYS

MemcacheDBI is a drop in replacement for DBI. It allows you to do trivial caching of some objects in a somewhat transactionally safe manner.

use MemcacheDBI;
my $dbh = MemcacheDBI->connect($data_source, $user, $password, {} ); # just like DBI
$dbh->memd_init(\%memcache_connection_args) # see Cache::Memcached::Fast

# Cache::Memcached::Fast should work using these calls
$dbh->memd->get();
$dbh->memd->set();
$memd = $dbh->memd; #get a handle you can use wherever

# DBI methods should all work as normal.  Additional new methods listed below
$dbh->prepare();
$dbh->execute();
etc

DESCRIPTION

Attach your memcached to your DBH handle. By doing so we can automatically queue set/get calls so that they happen at the same time as a commit. If a rollback is issued then the queue will be cleared.

CAVEATS

As long as DBI and Memcache are both up and running your fine. However this module will experience race conditions when one or the other goes down. We are currently working to see if some of this can be minimized, but be aware it is impossible to protect you if the DB/Memcache servers go down.

METHODS

memd_init

Normally you would use a MemcacheDBI->connect to create a new handle. However if you already have a DBH handle you can use this method to create a MemcacheDBI object using your existing handle.

Accepts a the following data types

Cache::Memcached::Fast (new Cache::Memcached::Fast)
A DBI handle (DBI->connect)
HASH of arguments to pass to new Cache::Memcached::Fast

memd

Get a memcache object that supports get/set/transactions

DBI methods can also be used, including but not limited to:

connect

The same as DBI->connect, returns a MemcacheDBI object so you can get your additional memcache functionality

commit

The same as DBI->commit, however it will also commit the memcached queue

rollback

The same as DBI->rollback, however it will also rollback the memcached queue

REPOSITORY

The code is available on github:

https://github.com/oaxlin/MemcacheDBI.git

DISCLAIMER

THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.