bug 4865: Enable session storage in Memcached
authorChris Cormack <chrisc@catalyst.net.nz>
Sun, 3 Apr 2011 02:36:42 +0000 (22:36 -0400)
committerChris Cormack <chrisc@catalyst.net.nz>
Sun, 3 Apr 2011 22:38:50 +0000 (10:38 +1200)
Note: this requires CGI::Session::Driver::memcached to be installed

Signed-off-by: Galen Charlton <gmcharlt@gmail.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
C4/Auth.pm
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref

index cecf8f8..35c0838 100644 (file)
@@ -34,7 +34,7 @@ use C4::VirtualShelves;
 use POSIX qw/strftime/;
 
 # use utf8;
-use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout);
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout $servers $memcached);
 
 BEGIN {
     $VERSION = 3.02;        # set version for version checking
@@ -54,7 +54,17 @@ BEGIN {
         require C4::Auth_with_cas;             # no import
         import  C4::Auth_with_cas qw(checkpw_cas login_cas logout_cas login_cas_url);
     }
-
+    $servers = C4::Context->config('memcached_servers');
+    $memcached;
+    if ($servers) {
+       require Cache::Memcached;
+        $memcached = Cache::Memcached->new({
+                                              servers => [ $servers ],
+                                              debug   => 0,
+                                              compress_threshold => 10_000,
+                                              namespace => C4::Context->config('memcached_namespace') || 'koha',
+                                          });
+    }
 }
 
 =head1 NAME
@@ -1346,6 +1356,9 @@ sub get_session {
     elsif ($storage_method eq 'Pg') {
         $session = new CGI::Session("driver:PostgreSQL;serializer:yaml;id:md5", $sessionID, {Handle=>$dbh});
     }
+    elsif ($storage_method eq 'memcached' && $servers){
+       $session = new CGI::Session("driver:memcached;serializer:yaml;id:md5", $sessionID, { Memcached => $memcached } );
+    }
     else {
         # catch all defaults to tmp should work on all systems
         $session = new CGI::Session("driver:File;serializer:yaml;id:md5", $sessionID, {Directory=>'/tmp'});
index 3ef972b..a2ecc5c 100644 (file)
@@ -69,6 +69,7 @@ Administration:
                   mysql: in the MySQL database.
                   Pg: in the PostgreSQL database (not supported).
                   tmp: as temporary files.
+                  memcached: in a memcached server.
         -
             - pref: IndependantBranches
               default: 0