[Koha-patches] [PATCH] cache the session for the duration of the script
Michael Hafen
mdhafen at tech.washk12.org
Thu May 6 22:43:12 CEST 2010
cache the CGI::Session object in C4::Context for the duration of the script.
This should help pages like circulation.pl which call get_session() again.
---
C4/Auth.pm | 4 ++++
C4/Context.pm | 33 +++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/C4/Auth.pm b/C4/Auth.pm
index 4f76ea6..79836d0 100644
--- a/C4/Auth.pm
+++ b/C4/Auth.pm
@@ -1343,6 +1343,9 @@ sub get_session {
my $storage_method = C4::Context->preference('SessionStorage');
my $dbh = C4::Context->dbh;
my $session;
+ if ( $sessionID && defined ( $session = C4::Context->session( $sessionID ) ) ) {
+ return $session;
+ }
if ($storage_method eq 'mysql'){
$session = new CGI::Session("driver:MySQL;serializer:yaml;id:md5", $sessionID, {Handle=>$dbh});
}
@@ -1353,6 +1356,7 @@ sub get_session {
# catch all defaults to tmp should work on all systems
$session = new CGI::Session("driver:File;serializer:yaml;id:md5", $sessionID, {Directory=>'/tmp'});
}
+ C4::Context->set_session( $session->id, $session );
return $session;
}
diff --git a/C4/Context.pm b/C4/Context.pm
index 926c1a5..5ea3e3d 100644
--- a/C4/Context.pm
+++ b/C4/Context.pm
@@ -903,6 +903,39 @@ sub _new_stopwords
return $stopwordlist;
}
+=item session
+
+ C4::Context->session;
+
+Retrieves the active CGI::Session object
+
+=cut
+
+sub session {
+ my $self = shift;
+ my $sess_id = shift;
+ return $context->{"session"}->{$sess_id} if (defined $sess_id and $sess_id and defined $context->{"session"}->{$sess_id});
+ return;
+}
+
+=item set_session
+
+ C4::Context->set_session
+
+Caches the active CGI::Session object
+
+=cut
+
+sub set_session {
+ my $self = shift;
+ my $id = shift;
+ my $session = shift;
+
+ return unless ( defined $id && defined $session && $id && $session );
+ $context->{"session"}->{ $id } = $session;
+ return $session;
+}
+
=item userenv
C4::Context->userenv;
--
1.7.0.4
More information about the Koha-patches
mailing list