summaryrefslogtreecommitdiff
path: root/includes/objectcache/ObjectCacheSessionHandler.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-06-04 07:31:04 +0200
committerPierre Schmitz <pierre@archlinux.de>2015-06-04 07:58:39 +0200
commitf6d65e533c62f6deb21342d4901ece24497b433e (patch)
treef28adf0362d14bcd448f7b65a7aaf38650f923aa /includes/objectcache/ObjectCacheSessionHandler.php
parentc27b2e832fe25651ef2410fae85b41072aae7519 (diff)
Update to MediaWiki 1.25.1
Diffstat (limited to 'includes/objectcache/ObjectCacheSessionHandler.php')
-rw-r--r--includes/objectcache/ObjectCacheSessionHandler.php38
1 files changed, 29 insertions, 9 deletions
diff --git a/includes/objectcache/ObjectCacheSessionHandler.php b/includes/objectcache/ObjectCacheSessionHandler.php
index cdf8da1e..789f1e3b 100644
--- a/includes/objectcache/ObjectCacheSessionHandler.php
+++ b/includes/objectcache/ObjectCacheSessionHandler.php
@@ -28,6 +28,9 @@
* @ingroup Cache
*/
class ObjectCacheSessionHandler {
+ /** @var array Map of (session ID => SHA-1 of the data) */
+ protected static $hashCache = array();
+
/**
* Install a session handler for the current web request
*/
@@ -49,10 +52,11 @@ class ObjectCacheSessionHandler {
/**
* Get the cache storage object to use for session storage
- * @return ObjectCache
+ * @return BagOStuff
*/
- static function getCache() {
+ protected static function getCache() {
global $wgSessionCacheType;
+
return ObjectCache::getInstance( $wgSessionCacheType );
}
@@ -62,11 +66,19 @@ class ObjectCacheSessionHandler {
* @param string $id Session id
* @return string Cache key
*/
- static function getKey( $id ) {
+ protected static function getKey( $id ) {
return wfMemcKey( 'session', $id );
}
/**
+ * @param mixed $data
+ * @return string
+ */
+ protected static function getHash( $data ) {
+ return sha1( serialize( $data ) );
+ }
+
+ /**
* Callback when opening a session.
*
* @param string $save_path Path used to store session files, unused
@@ -95,22 +107,29 @@ class ObjectCacheSessionHandler {
*/
static function read( $id ) {
$data = self::getCache()->get( self::getKey( $id ) );
- if ( $data === false ) {
- return '';
- }
- return $data;
+
+ self::$hashCache = array( $id => self::getHash( $data ) );
+
+ return ( $data === false ) ? '' : $data;
}
/**
* Callback when writing session data.
*
* @param string $id Session id
- * @param mixed $data Session data
+ * @param string $data Session data
* @return bool Success
*/
static function write( $id, $data ) {
global $wgObjectCacheSessionExpiry;
- self::getCache()->set( self::getKey( $id ), $data, $wgObjectCacheSessionExpiry );
+
+ // Only issue a write if anything changed (PHP 5.6 already does this)
+ if ( !isset( self::$hashCache[$id] )
+ || self::getHash( $data ) !== self::$hashCache[$id]
+ ) {
+ self::getCache()->set( self::getKey( $id ), $data, $wgObjectCacheSessionExpiry );
+ }
+
return true;
}
@@ -122,6 +141,7 @@ class ObjectCacheSessionHandler {
*/
static function destroy( $id ) {
self::getCache()->delete( self::getKey( $id ) );
+
return true;
}