Merge "(bug 38093) Gender of changed user groups missing in log"
[lhc/web/wiklou.git] / includes / cache / MemcachedSessions.php
1 <?php
2 /**
3 * Session storage in object cache.
4 *
5 * This file gets included if $wgSessionsInMemcache is set in the config.
6 * It redirects session handling functions to store their data in memcached
7 * instead of the local filesystem. Depending on circumstances, it may also
8 * be necessary to change the cookie settings to work across hostnames.
9 * See: http://www.php.net/manual/en/function.session-set-save-handler.php
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 * http://www.gnu.org/copyleft/gpl.html
25 *
26 * @file
27 * @ingroup Cache
28 */
29
30 /**
31 * Get a cache key for the given session id.
32 *
33 * @param $id String: session id
34 * @return String: cache key
35 */
36 function memsess_key( $id ) {
37 return wfMemcKey( 'session', $id );
38 }
39
40 /**
41 * Callback when opening a session.
42 * NOP: $wgMemc should be set up already.
43 *
44 * @param $save_path String: path used to store session files, unused
45 * @param $session_name String: session name
46 * @return Boolean: success
47 */
48 function memsess_open( $save_path, $session_name ) {
49 return true;
50 }
51
52 /**
53 * Callback when closing a session.
54 * NOP.
55 *
56 * @return Boolean: success
57 */
58 function memsess_close() {
59 return true;
60 }
61
62 /**
63 * Callback when reading session data.
64 *
65 * @param $id String: session id
66 * @return Mixed: session data
67 */
68 function memsess_read( $id ) {
69 global $wgMemc;
70 $data = $wgMemc->get( memsess_key( $id ) );
71 if( ! $data ) return '';
72 return $data;
73 }
74
75 /**
76 * Callback when writing session data.
77 *
78 * @param $id String: session id
79 * @param $data Mixed: session data
80 * @return Boolean: success
81 */
82 function memsess_write( $id, $data ) {
83 global $wgMemc;
84 $wgMemc->set( memsess_key( $id ), $data, 3600 );
85 return true;
86 }
87
88 /**
89 * Callback to destroy a session when calling session_destroy().
90 *
91 * @param $id String: session id
92 * @return Boolean: success
93 */
94 function memsess_destroy( $id ) {
95 global $wgMemc;
96
97 $wgMemc->delete( memsess_key( $id ) );
98 return true;
99 }
100
101 /**
102 * Callback to execute garbage collection.
103 * NOP: Memcached performs garbage collection.
104 *
105 * @param $maxlifetime Integer: maximum session life time
106 * @return Boolean: success
107 */
108 function memsess_gc( $maxlifetime ) {
109 return true;
110 }
111
112 function memsess_write_close() {
113 session_write_close();
114 }
115