MemcacheDBI - Queue memcache calls when in a dbh transaction
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
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.
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.
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
Get a memcache object that supports get/set/transactions
The same as DBI->connect, returns a MemcacheDBI object so you can get your additional memcache functionality
The same as DBI->commit, however it will also commit the memcached queue
The same as DBI->rollback, however it will also rollback the memcached queue
The code is available on github:
https://github.com/oaxlin/MemcacheDBI.git
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.
To install MemcacheDBI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MemcacheDBI
CPAN shell
perl -MCPAN -e shell install MemcacheDBI
For more information on module installation, please visit the detailed CPAN module installation guide.