CGI-Session-Driver-memcache
view release on metacpan or search on metacpan
memcache.pm view on Meta::CPAN
See F<README> in the package for short tutorials on setting up the memcached
server and testing the installation from command line.
=head1 BUGS
This driver requires Memcached connection handle to be passed to CGI::Session constructor as "raw" connection handle ({'Handle' => $memd}), making
caller responsible for passing a valid connection. This is actually good for relieving CGI::Session from the intricacies of suppporting various Memcached client
modules with differences in constructions (the rest of the main API on these module is generally very similar).
This driver and CGI::Session underpinnings do very little to ensure the server is actually alive.
The situation is even worse for Memcached client modules that return valid client instance
without server running (This is very different from lot of other DB Modules like DBI/DBD* or Net::LDAP,
where any problems with server raises exceptions or returns undefined handles).
Make sure your server is alive by either Calling stats() on Memcached client:
my $stats = $memd->stats(); # Allows: [$keys]
if (ref($stats) || !$stats->{'total'}) {die("No stats from Memcached - Memcached not running ?");}
... or by doing a set/get test sequence:
my $testval = "it_is_".time();
my $ok = $memd->set("whatstime", $testval);
if (!$ok) {die("Setting k-v in memcached failed - Memcached not running ?");}
# Optional get to double verify reading back
t/02testlocalmemcached.t view on Meta::CPAN
plan('tests', 6);
my $memd = Cache::Memcached->new({
'servers' => [ "$memdhost:11211" ], 'debug' => 0,
});
if (!$memd) {die("Failed to instantiate memcached Server Connection to '$memdhost'");}
ok($memd, "Got Memcached connection to '$memdhost'");
isa_ok($memd, 'Cache::Memcached');
my $s = $memd->stats();
ok($s, "Got stats (to see server is alive)"); # .Dumper($s)
ok(ref($s) eq 'HASH', "Stats Returned in HASH");
#
my $key = "from.$$";
my $val1 = "Hello $$";
my $ok = $memd->set($key, "Hello $$");
ok($ok, "Sent k-v successfully ('$key', '$val1')");
#
my $val = $memd->get($key);
ok($val eq $val1, "Got identical value back ('$val') for key '$key'");
t/03overhttp.t view on Meta::CPAN
#my $cpid = $server->background()
#NA:$server->run();
ok($cpid, "Started up HTTP Server for testing (PID: $cpid)");
#isa_ok($server, 'HTTP::Server::Simple');
}
##### CLIENT ###########
my $url = "http://localhost:$port/foo";
note("Use WWW::Mechanize HTTP Client to test session creation");
use_ok('WWW::Mechanize');
my $mech = WWW::Mechanize->new('keep_alive' => 1, 'cookie_jar' => {});
ok($mech, "Launched HTTP User agent to test with (Mechanize: $WWW::Mechanize::VERSION)");
sub cont4url {
my ($mech, $url) = @_;
#note("Call URL: $url");
my $resp = $mech->get($url);
ok($resp, "Got resp: $resp");
my $cont = $resp->content();
my $len = length($cont);
ok($cont, "Got Content ($len B)");
# Detect presence of cookie
( run in 2.487 seconds using v1.01-cache-2.11-cpan-df04353d9ac )