The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Apache::Session::Store::libmemcached - Memcached::libmemcached

VERSION

Version 0.01

SYNOPSIS

  use Apache::Session::libmemcache

  tie %hash, 'Apache::Session::libmemcache', $id, {
      servers => ['1.2.3.4:2100', '4.3.2.1:2100'],
      expiration => 300, # In seconds
      log_errors => 1,
  }

  # to enable a simple load balancing feature
  # and/or fail over
  tie %hash, 'Apache::Session::libmemcache', $id, {
     load_balance => [
        ['1.2.3.4:2100', '4.3.2.1:2100'],
        ['1.1.1.1:2100', '2.2.2.2:2100'],
     ],
     failover => 1,
     expiration => 300, # In seconds
     log_errors => 1,
  };

DESCRIPTION

Apache::Session::Store::libmemcached fulfills the storage interface of Apache::Session. Session data is stored memcached using Memcached::libmemcached

CONFIGURATION

servers

Array reference containing strings with the format server:port. You can include multiple servers.

expiration

Optional parameter that sets the xpiration time of the session. This is takes advantage of a memcached feature that allows to set keys with expiration time. 0, undef sets no expiration time.

log_errors

If this parameter is set to 1, error messages will be outputed to STDERR if a memcached operation fails.

LOAD BALANCE AND FAILOVER

load_balance

You can use this paramater instead of servers. It takes multiple server pools. Each pool is represented by an array reference containing strings with the format server:port.

When this parameter is used read operations will be 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.

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.

METHODS

new

insert

Insert a session id into memcached. It will die if the key already exists.

update

Replace a session id into memcached.

materialize

Retrieve the content of a session id

remove

Remove a session id from mecached

_connect

Private method that takes care of connecting to the memcache servers.

_read_session

Private method to read sessions.

If load balance is enabled it will read from the right cache.

If it fails and failover is enabled, it will try to read from other pools.

_select_read_pool

Private method to select a pool to read from.

We just use 'first session id character' mod $numberOfPools to select a pool.

Note that we return the first available pool if load balance is not enabled or if there is only one pool.

_update_pools

Private method to return which pools must be updated.

If failover is not enabled only one pool is returned. Otherwise the designated pool will be returned.

_read_from_pool

Private method to read from a given pool.

If read fails it will log the error in case logging is enabled.

_write_session

Private method to set a key-value entry in all the configured pools.

_log_error_message

Private method to log error messages

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Apache::Session::libmemcached

AUTHOR

Javier Uruen Val <javi.uruen@gmail.com>

LICENSE AND COPYRIGHT

Copyright (C) 2010 Venda Ltd

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.