Apache-Session-Memorycached

 view release on metacpan or  search on metacpan

lib/Apache/Session/Memorycached.pm  view on Meta::CPAN

#############################################################################
#
# Apache::Session::Memorycached
# Apache persistent user sessions on the network with memcached
# Copyright(c) eric german <germanlinux@yahoo.fr>
# Distribute under the Artistic License
#
############################################################################

package Apache::Session::Memorycached;

use strict;
use vars qw(@ISA $VERSION);

$VERSION = '2.2.1';
@ISA = qw(Apache::Session);

use Apache::Session;
use Apache::Session::Generate::MD5;
use Apache::Session::Lock::Memorycached;
use Apache::Session::Store::Memorycached;

sub populate {
    my $self = shift;

    $self->{object_store} = new Apache::Session::Store::Memorycached $self;
    $self->{lock_manager} = new Apache::Session::Lock::Memorycached $self;
    $self->{generate}     = \&Apache::Session::Generate::MD5::generate;
    $self->{validate}     = \&Apache::Session::Generate::MD5::validate;
    $self->{serialize}    = \&Apache::Session::Memorycached::none;
    $self->{unserialize}  = \&Apache::Session::Memorycached::none;

    return $self;
}

sub none {
    my $self    = shift;
    my $session = shift;
return;
 }
 sub DESTROY {
    my $self = shift;
    
    $self->save;
    $self->{object_store}->close;
    $self->release_all_locks;
}

1;


=pod

=head1 NAME

Apache::Session::Memorycached - An implementation of Apache::Session

=head1 SYNOPSIS

 use Apache::Session::Memorycached;
 
    tie %session, 'Apache::Session::Memorycached', $cookie, {
          'servers' => ["10.75.1.19:11211"], #all write operations
          'local'  =>  ["localhost:11211"],  #read-only operations
          'timeout' => '300'
     };

 tie %s, 'Apache::Session::Memorycached', undef,
    {servers  => ['mymemcachedserver:port'],
     'timeout' => '300',
     'updateOnly' => 1 ,
     'principal' => uid,  
        };

In order to optimize the network ,you can use a local memcached server.
All read-only opération are sending fisrt at local server .If you need write ou rewrite data , the data is sending at the principal memcached sever and local cache too  for synchronisation.

note :  'updateOnly' => 1  just realize up-date operation not init operation. 
 Init operation is use in order to book and lock the number session but it's not available in this module 
 
  'principal' => uid :  this  parameter is use to create reverse reference 
  like this : MD5_hex(uid) => id_session in memcached server . By this it usefull to retrieve id_session from principal name . And add uid_MD5 => MD5_hex(uid) in main session .
 




=head1 DESCRIPTION



( run in 1.772 second using v1.01-cache-2.11-cpan-39bf76dae61 )