Lemonldap-NG-Common

 view release on metacpan or  search on metacpan

lib/Lemonldap/NG/Common/Apache/Session/Store.pm  view on Meta::CPAN


package Lemonldap::NG::Common::Apache::Session::Store;

use strict;

our $VERSION = '2.19.0';

sub new {
    my $class = shift;
    return bless {}, $class;
}

sub insert {
    my $self    = shift;
    my $session = shift;
    $self->{args} = $session->{args};

    # Store session in cache
    my $id = $session->{data}->{_session_id};
    $self->storeInCache( $id, $session->{serialized} );

    # Store in session backend
    return $self->module->insert($session);
}

sub update {
    my $self    = shift;
    my $session = shift;
    $self->{args} = $session->{args};

    #TODO: remove cache on all LL::NG instances if updateCache == 1

    unless ( defined( $session->{args}->{updateCache} )
        and $session->{args}->{updateCache} == -1 )
    {

        # Update session in cache
        my $id = $session->{data}->{_session_id};
        $self->removeFromCache($id) if ( $self->getFromCache($id) );
        $self->storeInCache( $id, $session->{serialized} );
    }

    unless ( defined( $session->{args}->{updateCache} )
        and $session->{args}->{updateCache} == 2 )
    {

        # Update session in backend
        return $self->module->update($session);
    }
}

sub materialize {
    my $self    = shift;
    my $session = shift;
    $self->{args} = $session->{args};

    # Get session from cache
    my $id = $session->{data}->{_session_id};
    if ( !$self->{args}->{noCache} and $self->getFromCache($id) ) {
        $session->{serialized} = $self->getFromCache($id);
        eval { JSON::from_json( $session->{serialized} ); };
        if ($@) {
            print STDERR "Local data corrupted, ignore cached session\n";
            $session->{serialized} = undef;
        }
        else {
            return;
        }
    }

    # Get session from backend
    $self->module->materialize($session);

    # Store session in cache
    $self->storeInCache( $id, $session->{serialized} );

    return;
}

sub remove {
    my $self    = shift;
    my $session = shift;
    $self->{args} = $session->{args};

    #TODO: remove cache on all LL::NG instances if updateCache == 1



( run in 2.121 seconds using v1.01-cache-2.11-cpan-600a1bdf6e4 )