| Index: trunk/phase3/includes/ObjectCache.php |
| — | — | @@ -31,7 +31,7 @@ |
| 32 | 32 | var $debugmode; |
| 33 | 33 | |
| 34 | 34 | function BagOStuff() { |
| 35 | | - set_debug( false ); |
| | 35 | + $this->set_debug( false ); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function set_debug($bool) { |
| — | — | @@ -56,6 +56,16 @@ |
| 57 | 57 | return false; |
| 58 | 58 | } |
| 59 | 59 | |
| | 60 | + function lock($key, $timeout = 0) { |
| | 61 | + /* stub */ |
| | 62 | + return true; |
| | 63 | + } |
| | 64 | + |
| | 65 | + function unlock($key) { |
| | 66 | + /* stub */ |
| | 67 | + return true; |
| | 68 | + } |
| | 69 | + |
| 60 | 70 | /* *** Emulated functions *** */ |
| 61 | 71 | /* Better performance can likely be got with custom written versions */ |
| 62 | 72 | function get_multi($keys) { |
| — | — | @@ -93,27 +103,36 @@ |
| 94 | 104 | } |
| 95 | 105 | |
| 96 | 106 | function incr($key, $value=1) { |
| | 107 | + if ( !$this->lock($key) ) { |
| | 108 | + return false; |
| | 109 | + } |
| 97 | 110 | $value = intval($value); |
| 98 | 111 | if($value < 0) $value = 0; |
| | 112 | + |
| | 113 | + $n = false; |
| 99 | 114 | if( ($n = $this->get($key)) !== false ) { |
| 100 | | - $this->set($key, $n+$value); // exptime? |
| 101 | | - return $n+$value; |
| 102 | | - } else { |
| 103 | | - return false; |
| | 115 | + $n += $value; |
| | 116 | + $this->set($key, $n); // exptime? |
| 104 | 117 | } |
| | 118 | + $this->unlock($key); |
| | 119 | + return $n; |
| 105 | 120 | } |
| 106 | 121 | |
| 107 | 122 | function decr($key, $value=1) { |
| | 123 | + if ( !$this->lock($key) ) { |
| | 124 | + return false; |
| | 125 | + } |
| 108 | 126 | $value = intval($value); |
| 109 | 127 | if($value < 0) $value = 0; |
| | 128 | + |
| | 129 | + $m = false; |
| 110 | 130 | if( ($n = $this->get($key)) !== false ) { |
| 111 | 131 | $m = $n - $value; |
| 112 | 132 | if($m < 0) $m = 0; |
| 113 | 133 | $this->set($key, $m); // exptime? |
| 114 | | - return $m; |
| 115 | | - } else { |
| 116 | | - return false; |
| 117 | 134 | } |
| | 135 | + $this->unlock($key); |
| | 136 | + return $m; |
| 118 | 137 | } |
| 119 | 138 | |
| 120 | 139 | function _debug($text) { |
| — | — | @@ -312,4 +331,29 @@ |
| 313 | 332 | } |
| 314 | 333 | } |
| 315 | 334 | |
| | 335 | +class TurckBagOStuff extends BagOStuff { |
| | 336 | + function get($key) { |
| | 337 | + return mmcache_get( $key ); |
| | 338 | + } |
| | 339 | + |
| | 340 | + function set($key, $value, $exptime=0) { |
| | 341 | + mmcache_put( $key, $value, $exptime ); |
| | 342 | + return true; |
| | 343 | + } |
| | 344 | + |
| | 345 | + function delete($key, $time=0) { |
| | 346 | + mmcache_rm( $key ); |
| | 347 | + return true; |
| | 348 | + } |
| | 349 | + |
| | 350 | + function lock($key, $waitTimeout = 0 ) { |
| | 351 | + mmcache_lock( $key ); |
| | 352 | + return true; |
| | 353 | + } |
| | 354 | + |
| | 355 | + function unlock($key) { |
| | 356 | + mmcache_unlock( $key ); |
| | 357 | + return true; |
| | 358 | + } |
| | 359 | +} |
| 316 | 360 | ?> |
| Index: trunk/phase3/includes/DefaultSettings.php |
| — | — | @@ -131,7 +131,12 @@ |
| 132 | 132 | $wgSessionsInMemcached = false; |
| 133 | 133 | $wgLinkCacheMemcached = false; # Not fully tested |
| 134 | 134 | |
| | 135 | +# Turck MMCache shared memory |
| | 136 | +# You can use this for persistent caching where your wiki runs on a small number of |
| | 137 | +# servers. Mutually exclusive with memcached. MMCache must be installed. |
| | 138 | +$wgUseTurckShm = false; |
| 135 | 139 | |
| | 140 | + |
| 136 | 141 | # Language settings |
| 137 | 142 | # |
| 138 | 143 | $wgLanguageCode = 'en'; |
| Index: trunk/phase3/includes/Setup.php |
| — | — | @@ -122,7 +122,15 @@ |
| 123 | 123 | $wgMemc->set_debug( $wgMemCachedDebug ); |
| 124 | 124 | |
| 125 | 125 | $messageMemc = &$wgMemc; |
| | 126 | +} elseif ( $wgUseTurckShm ) { |
| | 127 | + # Turck shared memory |
| | 128 | + # |
| | 129 | + require_once( 'ObjectCache.php' ); |
| | 130 | + $wgMemc = new TurckBagOStuff; |
| | 131 | + $messageMemc = &$wgMemc; |
| 126 | 132 | } else { |
| | 133 | + # No shared memory |
| | 134 | + # |
| 127 | 135 | class FakeMemCachedClient { |
| 128 | 136 | function add ($key, $val, $exp = 0) { return true; } |
| 129 | 137 | function decr ($key, $amt=1) { return null; } |