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();
$dbh->memd_commit(); # not a memcache call
# 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
The same as Cache::Memcached::Fast::get
memd_set
The same as Cache::Memcached::Fast::set
memd_commit
memd_commit only commits the memcache data, if you want to commit both simply use $obj->commit instead.
dbh_commit
dbh_commit only commits the dbh data, if you want to commit both simply use $obj->commit instead.
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.