From d00451fa194a95aef81eaa966713950f32db43a3 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 23 Oct 2004 10:21:23 +0000 Subject: [PATCH] Fixed bug with Turck MMCache wrapper, and made it the default where Turck is installed (except if memcached is specified) --- includes/DefaultSettings.php | 8 ++++---- includes/ObjectCache.php | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 825f5ecb87..758863a367 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -277,13 +277,13 @@ $wgLinkCacheMemcached = false; # Not fully tested /** * Turck MMCache shared memory - * You can use this for persistent caching where your wiki runs on a small - * number of servers. Mutually exclusive with memcached. MMCache must be - * installed. + * You can use this for persistent caching where your wiki runs on a single + * server. Enabled by default if Turck is installed. Mutually exclusive with + * memcached, memcached is used if both are specified. * * @global bool $wgUseTurckShm Enable or disabled Turck MMCache */ -$wgUseTurckShm = false; +$wgUseTurckShm = function_exists( 'mmcache_get' ); # Language settings diff --git a/includes/ObjectCache.php b/includes/ObjectCache.php index ecbf731d80..7e182d8d21 100644 --- a/includes/ObjectCache.php +++ b/includes/ObjectCache.php @@ -370,16 +370,31 @@ class MediaWikiBagOStuff extends SqlBagOStuff { } /** - * @todo document + * This is a wrapper for Turck MMCache's shared memory functions. + * + * You can store objects with mmcache_put() and mmcache_get(), but Turck seems + * to use a weird custom serializer that randomly segfaults. So we wrap calls + * with serialize()/unserialize(). + * + * The thing I noticed about the Turck serialized data was that unlike ordinary + * serialize(), it contained the names of methods, and judging by the amount of + * binary data, perhaps even the bytecode of the methods themselves. It may be + * that Turck's serializer is faster, so a possible future extension would be + * to use it for arrays but not for objects. + * * @package MediaWiki */ class TurckBagOStuff extends BagOStuff { function get($key) { - return mmcache_get( $key ); + $val = mmcache_get( $key ); + if ( is_string( $val ) ) { + $val = unserialize( $val ); + } + return $val; } function set($key, $value, $exptime=0) { - mmcache_put( $key, $value, $exptime ); + mmcache_put( $key, serialize( $value ), $exptime ); return true; } -- 2.20.1