New feature: Turck MMCache shared memory as a lightweight, windows-compatible replace...
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 21 Aug 2004 13:59:48 +0000 (13:59 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 21 Aug 2004 13:59:48 +0000 (13:59 +0000)
includes/DefaultSettings.php
includes/ObjectCache.php
includes/Setup.php

index 91b5cb2..adde97b 100644 (file)
@@ -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
 #
index 18705d0..093f671 100644 (file)
@@ -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;
+       }
+}      
 ?>
index 22f8585..0dfdb4c 100644 (file)
@@ -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; }