24 Feb 2011 14:33:50 UTC
- Distribution: Memcached-Client
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (4)
- Testers (2510 / 304 / 0)
- KwaliteeBus factor: 0
- 49.41% Coverage
- License: perl_5
- Activity24 month
- Download (36.53KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionMDORMAN Michael Alan Dorman
Memcached::Clientis the central hub
During the loading of the
Memcached::Client::Requestmodule, we insert a bunch of methods into the
Memcached::Clientnamespace that are really just curried functions that create instances of the various
When you make a request, things go like this (using
getas an example):
$client->getcalls the anonymous subroutine that was returned when
M::C::Request::Get->generate(which, due to inheritance, is
M::C::Request->generate) was called.
The anonymous sub expects the
Memcached::Clientobject as its first parameter, and uses the remainder as arguments for its command. The command that was curried in when the subroutine was created is used to construct a hashref that will become the request object.
The last argument to the subroutine is examined. If it was something we can use as a callback (either a
CODEreference or an
AnyEvent::CondVar, it is stored, and we assume that somewhere else in the calling program there is a statement waiting on an
AnyEvent::CondVar---so we will not be obliged to do so ourselves in order for the request to get processed.
Otherwise we create the aforementioned
AnyEvent::CondVarand mark ourselves as needing to wait.
We then hand the rest of our arguments to the
processroutine, which is supposed to verify the object's arguments and returns one or more
Requestobjects to be submitted to the appropriate server(s). If it does not return any objects, it is assumed that there was a problem with the submission, and an empty result is returned.
__submitroutine in the
Memcached::Clientmodule is handed the request objects to process.
__submititerates through the objects, looking at whether they include a
keymember. If they do, the key is processed to determine what server it should be directed at, checked for validity, and if it's OK, it is submitted to the appropriate server's queue using the connection's
If the object doesn't have a
key, it is assumed to be a broadcast message destined for all servers, and
__submituses the object's
serverfactory to create subrequests for each server.
The connection object works its way through its queue (if there's nothing else in the queue when you add a new request, it will be handled immediately, but that's just an optimization) and comes to your request object.
It gets the name of the protocol function from your request object, and invokes that method on the protocol object, passing it a reference to itself and your request.
The protocol method constructs the command from the data members of the request object and submits it to the connection object.
When the response to the request has been recieved the protocol object decodes it and sends the result back to the request object using its
resultmethod, and notifies the connection that it's done with the request by calling
Module Install Instructions
To install Memcached::Client, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Memcached::Client
For more information on module installation, please visit the detailed CPAN module installation guide.