LL::NG::Common::Session: add option updateCache to update() and remove() (#724)

environments/ppa-mbqj77/deployments/1
François-Xavier Deltombe 11 years ago
parent e2feaf796d
commit b0e41fd796
  1. 32
      lemonldap-ng-common/lib/Lemonldap/NG/Common/Apache/Session/Store.pm
  2. 16
      lemonldap-ng-common/lib/Lemonldap/NG/Common/Session.pm

@ -26,15 +26,19 @@ sub update {
my $session = shift;
$self->{args} = $session->{args};
# Update session in cache
my $id = $session->{data}->{_session_id};
if ( $self->cache->get($id) ) {
$self->cache->remove($id);
#TODO: remove cache on all LL::NG instances if updateCache == 1
unless ( $session->{args}->{updateCache} == -1 ) {
# Update session in cache
my $id = $session->{data}->{_session_id};
$self->cache->remove($id) if ( $self->cache->get($id) );
$self->cache->set( $id, $session->{serialized} );
}
# Update session in backend
return $self->module->update($session);
unless ( $session->{args}->{updateCache} == 2 ) {
# Update session in backend
return $self->module->update($session);
}
}
sub materialize {
@ -63,14 +67,18 @@ sub remove {
my $session = shift;
$self->{args} = $session->{args};
# Remove session from cache
my $id = $session->{data}->{_session_id};
if ( $self->cache->get($id) ) {
$self->cache->remove($id);
#TODO: remove cache on all LL::NG instances if updateCache == 1
unless ( $session->{args}->{updateCache} == -1 ) {
# Remove session from cache
my $id = $session->{data}->{_session_id};
$self->cache->remove($id) if ( $self->cache->get($id) );
}
# Remove session from backend
return $self->module->remove($session);
unless ( $session->{args}->{updateCache} == 2 ) {
# Remove session from backend
return $self->module->remove($session);
}
}
sub close {

@ -112,12 +112,13 @@ sub BUILD {
sub _tie_session {
my $self = shift;
my $options = shift || {};
my %h;
eval {
tie %h, 'Lemonldap::NG::Common::Apache::Session', $self->id,
$self->options;
{ %{ $self->options }, %$options };
};
return undef if ( $@ or not tied(%h) );
@ -135,10 +136,11 @@ sub _save_data {
sub update {
my $self = shift;
my $infos = shift;
my $tieOptions = shift;
return 0 unless ( ref $infos eq "HASH" );
my $data = $self->_tie_session;
my $data = $self->_tie_session($tieOptions);
if ($data) {
foreach ( keys %$infos ) {
@ -161,8 +163,9 @@ sub update {
sub remove {
my $self = shift;
my $tieOptions = shift;
my $data = $self->_tie_session;
my $data = $self->_tie_session($tieOptions);
eval { tied(%$data)->delete(); };
@ -170,13 +173,6 @@ sub remove {
return 1;
}
sub cacheUpdate {
my $self = shift;
# Update a data to force update from cache
return $self->update( { '_session_id' => $self->id } );
}
no Mouse;
1;

Loading…
Cancel
Save