From b0e41fd79632b40e71c193b93af13efa1e32bf0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Deltombe?= Date: Thu, 3 Jul 2014 09:33:19 +0000 Subject: [PATCH] LL::NG::Common::Session: add option updateCache to update() and remove() (#724) --- .../NG/Common/Apache/Session/Store.pm | 32 ++++++++++++------- .../lib/Lemonldap/NG/Common/Session.pm | 16 ++++------ 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Apache/Session/Store.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Apache/Session/Store.pm index 493816251..8c6f04fa3 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Apache/Session/Store.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Apache/Session/Store.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 { diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Session.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Session.pm index ea6e87a5a..7c450dd67 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Session.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Session.pm @@ -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;