Cache-Memcached-AnyEvent
view release on metacpan or search on metacpan
lib/Cache/Memcached/AnyEvent.pm view on Meta::CPAN
There's another alternative L<AnyEvent> memcached client, L<AnyEvent::Memcached> which is perfectly fine, and I have nothing against you using that module. I just have some specific itches to scratch:
=over 4
=item Prerequisites
This module, L<Cache::Memcached::AnyEvent>, requires the bare minimum prerequisites to install. L<AnyEvent::Memcached> requires AnyEvent::Connection and Object::Event ;) Those modules are fine, I just don't use them, so I don't want them.
=item Binary Protocol
I was in the mood to implement the binary protocol. I don't believe it's a requirement to do anything, so this is purely a whim. There's nothing that requires binary protocol in the wild, so it has no practactical advantages. I just wanted to impleme...
=item Cache::Memcached Interface
In general, this module follows the interface of Cache::Memcached.
=back
So choose according to your needs. If you for some reason don't want AnyEvent::Connection and Object::Event, want a binary protocol, and like to stick with Cache::Memcached interface (relatively speaking), then use this module. Otherwise, read the do...
=head1 METHODS
All methods interacting with a memcached server which can take a callback
function can also take a condvar instead. For example,
$memd->get( "foo", sub {
my $value = shift;
} );
is equivalent to
my $cv = AE::cv {
my $value = $_[0]->recv;
};
$memd->get( "foo", $cv );
# optionally, call $cv->recv here.
=head2 new(%args)
=over 4
=item auto_reconnect => $max_attempts
Set to 0 to disable auto-reconnecting
=item compress_threshold => $number
=item selector => $object
The selector is an object responsible for selecting the appropriate
Memcached server to store a particular key. This object MUST implement
the following methods:
$object->set_server( @servernames );
my $handle = $object->get_handle( $key );
By default if this argument is not specified, a selector object will
automatically be created using the value of the C<selector_class>
argument.
=item selector_class => $class_name_or_fragment
Specifies the selector class to be instantiated. The default value is "Traditional".
If the class name is preceded by a single '+', then that class name with the
'+' removed will be used as the class name. Otherwise, the prefix
"Cache::Memcached::AnyEvent::Selector::" will be added to the value
("Traditional" would be transformed to "Cache::Memcached::AnyEvent::Selector::Traditional")
=item namespace => $namespace
=item procotol => $object
The protocol is an object responsible for handling the actual talking to
the memcached servers. This object MUST implement all of the memcached
interface supported by Cache::Memcached::AnyEvent
By default if this argument is not specified, a protocol object will
automatically be created using the value of the C<protocol_class>
argument.
=item protocol_class => $classname
Specifies the protocol class to be instantiated. The default value is "Text".
If the class name is preceded by a single '+', then that class name with the
'+' removed will be used as the class name. Otherwise, the prefix
"Cache::Memcached::AnyEvent::Protocol::" will be added to the value
("Text" would be transformed to "Cache::Memcached::AnyEvent::Protocol::Text")
=item reconnect_delay => $seconds
Amount of time to wait between reconnect attempts
=item servers => \@servers
List of servers to use.
=back
C<%args> can also be a hashref.
=head2 auto_reconnect([$bool]);
Get/Set auto_reconnect flag.
=head2 add($key, $value[, $exptime, $noreply], $cb->($rc))
=head2 add_server( $host_port )
=head2 append($key, $value, $cb->($rc))
=head2 connect()
Explicitly connects to each server given. You DO NOT need to call this
explicitly.
=head2 decr($key, $delta[, $initial], $cb->($value))
=head2 delete($key, $cb->($rc))
( run in 1.673 second using v1.01-cache-2.11-cpan-364913b4093 )