Apache-Session-libmemcached
view release on metacpan or search on metacpan
lib/Apache/Session/Store/libmemcached.pm view on Meta::CPAN
=item load_balance
You can use this paramater instead of I<servers>. It takes multiple server
pools. Each pool is represented by an array reference containing strings with
the format I<server:port>.
When this parameter is used read operations will be I<load balanced> between the
available pools.
The current balancing method is pretty straightforward. It uses the first
character of the session identifier to select the pool. On average and given
random session indentifiers memcache operation will be evenly distributed
amongst the available pools.
=item failover
When failover is enabled, write operations take place in all the available
pools. Read operations are still load balanced. However, in the event of a read
operation fail, the other available pools will be used.
=back
=head1 METHODS
=head2 new
=cut
sub new {
my ($class, $session) = @_;
my $self = {};
bless ($self, $class);
$self->_connect($session);
return $self;
}
=head2 insert
Insert a session id into memcached. It will die if the key already exists.
=cut
sub insert {
my ($self, $session) = @_;
if ($self->_read_session($session)) {
die 'Object already exists in data store';
}
$self->_write_session(set => $session);
}
=head2 update
Replace a session id into memcached.
=cut
sub update {
my ($self, $session) = @_;
$self->_write_session(replace => $session);
}
=head2 materialize
Retrieve the content of a session id
=cut
sub materialize {
my ($self, $session) = @_;
if (my $value = $self->_read_session($session)) {
$session->{serialized} = $value;
}
else {
die 'Object does not exist in data store';
}
}
=head2 remove
Remove a session id from mecached
=cut
sub remove {
my ($self, $session) = @_;
my $args = $session->{args};
my $sid = $session->{data}->{_session_id};
for my $mcache (@{$self->{libmemcached}}) {
$mcache->{instance}->memcached_delete($sid);
}
}
=head2 _connect
Private method that takes care of connecting to the memcache servers.
=cut
sub _connect {
my ($self, $session) = @_;
my $args = $session->{args};
my @pools;
if ($args->{servers} && ref($args->{servers}) eq 'ARRAY') {
push (@pools, $args->{servers});
}
elsif ($args->{load_balance_pools}
&& ref($args->{load_balance_pools}) eq 'ARRAY'
) {
push (@pools, @{$args->{load_balance_pools}});
}
die 'No libmemcached server supplied' unless (@pools);
( run in 0.726 second using v1.01-cache-2.11-cpan-63c85eba8c4 )