From: Tim Starling Date: Sat, 21 Aug 2004 13:59:48 +0000 (+0000) Subject: New feature: Turck MMCache shared memory as a lightweight, windows-compatible replace... X-Git-Tag: 1.5.0alpha1~2272 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=bcb4f2c04695411121dec246f78e36c7655aaec6;p=lhc%2Fweb%2Fwiklou.git New feature: Turck MMCache shared memory as a lightweight, windows-compatible replacement for memcached --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 91b5cb287a..adde97bcb0 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -131,6 +131,11 @@ $wgMemCachedDebug = false; $wgSessionsInMemcached = false; $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. +$wgUseTurckShm = false; + # Language settings # diff --git a/includes/ObjectCache.php b/includes/ObjectCache.php index 18705d08d9..093f6716c2 100644 --- a/includes/ObjectCache.php +++ b/includes/ObjectCache.php @@ -31,7 +31,7 @@ class /* abstract */ BagOStuff { var $debugmode; function BagOStuff() { - set_debug( false ); + $this->set_debug( false ); } function set_debug($bool) { @@ -56,6 +56,16 @@ class /* abstract */ BagOStuff { return false; } + function lock($key, $timeout = 0) { + /* stub */ + return true; + } + + function unlock($key) { + /* stub */ + return true; + } + /* *** Emulated functions *** */ /* Better performance can likely be got with custom written versions */ function get_multi($keys) { @@ -93,27 +103,36 @@ class /* abstract */ BagOStuff { } function incr($key, $value=1) { + if ( !$this->lock($key) ) { + return false; + } $value = intval($value); if($value < 0) $value = 0; + + $n = false; if( ($n = $this->get($key)) !== false ) { - $this->set($key, $n+$value); // exptime? - return $n+$value; - } else { - return false; + $n += $value; + $this->set($key, $n); // exptime? } + $this->unlock($key); + return $n; } function decr($key, $value=1) { + if ( !$this->lock($key) ) { + return false; + } $value = intval($value); if($value < 0) $value = 0; + + $m = false; if( ($n = $this->get($key)) !== false ) { $m = $n - $value; if($m < 0) $m = 0; $this->set($key, $m); // exptime? - return $m; - } else { - return false; } + $this->unlock($key); + return $m; } function _debug($text) { @@ -312,4 +331,29 @@ class MediaWikiBagOStuff extends SqlBagOStuff { } } +class TurckBagOStuff extends BagOStuff { + function get($key) { + return mmcache_get( $key ); + } + + function set($key, $value, $exptime=0) { + mmcache_put( $key, $value, $exptime ); + return true; + } + + function delete($key, $time=0) { + mmcache_rm( $key ); + return true; + } + + function lock($key, $waitTimeout = 0 ) { + mmcache_lock( $key ); + return true; + } + + function unlock($key) { + mmcache_unlock( $key ); + return true; + } +} ?> diff --git a/includes/Setup.php b/includes/Setup.php index 22f85858e1..0dfdb4c392 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -121,8 +121,16 @@ if( $wgUseMemCached ) { $wgMemc->set_servers( $wgMemCachedServers ); $wgMemc->set_debug( $wgMemCachedDebug ); + $messageMemc = &$wgMemc; +} elseif ( $wgUseTurckShm ) { + # Turck shared memory + # + require_once( 'ObjectCache.php' ); + $wgMemc = new TurckBagOStuff; $messageMemc = &$wgMemc; } else { + # No shared memory + # class FakeMemCachedClient { function add ($key, $val, $exp = 0) { return true; } function decr ($key, $amt=1) { return null; }