|
From: Dave S. <dst...@ma...> - 2007-01-19 18:43:34
|
We are experimenting here with it, with good results on other SQL-based =
PHP software.=20
=20
I would like to try it with Perl, and have the API, but am having trouble =
setting variables into memcached, and could use some help.
=20
I am using code that takes a SQL command string, turns it into an MD5 =
hash, then sees it if can get the data from memcached. If not, it looks it =
up in SQL, and then stores it in memcached.
=20
Anyone try this? I have *NO* idea what I am doing with Perl since I am =
just a PHP guy.
=20
Thanks!
=20
sub get_memcached_object {
my ($sql) =3D @_;
use Digest::MD5;
my $md5 ;
$md5 =3D Digest::MD5->new;
$md5->add($sql) ;
my $md5_id =3D $md5->hexdigest ;
print "SQL hashed to $md5_id \n" ;
=20
use Cache::Memcached;
my $obj =3D Cache::Memcached->get("$md5_id");
if ($obj)
{
# return $obj if $obj;
print "$md5_id found in memcached \n" ;
return $obj;
}
=20
# $obj =3D $::db->selectrow_hashref("$sql") ;
my $dbh ;
$dbh =3D DBI->connect('DBI:Pg:dbname=3Dv3_mw_filter_rules; host=3Dour_h=
ostname, our_username, ourpassword,
{ PrintError =3D> 0,
AutoCommit =3D> 1,
InactiveDestroy =3D> 1
}
) ;
print "Requesting from SQL server: $sql \n" ;
$obj =3D $dbh->selectrow_hashref("$sql") ;
print "Settting object in memcached: $obj \n" ;
Cache::Memcached->set("$md5_id", $obj);
=20
my $obj ;
$obj =3D Cache::Memcached->get("$md5_id");
if ($obj)
{
# return $obj if $obj;
print "$md5_id found in memcached \n" ;
return $obj;
}
}
This message has been certified virus-free by MailWise Filter - The real-ti=
me, intelligent, e-mail firewall used to scan inbound and outbound messages =
for SPAM, Viruses and Content. =0A=0A For more information, please visit: http:=
//www.mailwise.com=0A
|