MediaWiki r4882 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r4881‎ | r4882 (on ViewVC)‎ | r4883 >
Date:13:59, 21 August 2004
Author:timstarling
Status:old
Tags:
Comment:
New feature: Turck MMCache shared memory as a lightweight, windows-compatible replacement for memcached
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/ObjectCache.php
@@ -31,7 +31,7 @@
3232 var $debugmode;
3333
3434 function BagOStuff() {
35 - set_debug( false );
 35+ $this->set_debug( false );
3636 }
3737
3838 function set_debug($bool) {
@@ -56,6 +56,16 @@
5757 return false;
5858 }
5959
 60+ function lock($key, $timeout = 0) {
 61+ /* stub */
 62+ return true;
 63+ }
 64+
 65+ function unlock($key) {
 66+ /* stub */
 67+ return true;
 68+ }
 69+
6070 /* *** Emulated functions *** */
6171 /* Better performance can likely be got with custom written versions */
6272 function get_multi($keys) {
@@ -93,27 +103,36 @@
94104 }
95105
96106 function incr($key, $value=1) {
 107+ if ( !$this->lock($key) ) {
 108+ return false;
 109+ }
97110 $value = intval($value);
98111 if($value < 0) $value = 0;
 112+
 113+ $n = false;
99114 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?
104117 }
 118+ $this->unlock($key);
 119+ return $n;
105120 }
106121
107122 function decr($key, $value=1) {
 123+ if ( !$this->lock($key) ) {
 124+ return false;
 125+ }
108126 $value = intval($value);
109127 if($value < 0) $value = 0;
 128+
 129+ $m = false;
110130 if( ($n = $this->get($key)) !== false ) {
111131 $m = $n - $value;
112132 if($m < 0) $m = 0;
113133 $this->set($key, $m); // exptime?
114 - return $m;
115 - } else {
116 - return false;
117134 }
 135+ $this->unlock($key);
 136+ return $m;
118137 }
119138
120139 function _debug($text) {
@@ -312,4 +331,29 @@
313332 }
314333 }
315334
 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+}
316360 ?>
Index: trunk/phase3/includes/DefaultSettings.php
@@ -131,7 +131,12 @@
132132 $wgSessionsInMemcached = false;
133133 $wgLinkCacheMemcached = false; # Not fully tested
134134
 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;
135139
 140+
136141 # Language settings
137142 #
138143 $wgLanguageCode = 'en';
Index: trunk/phase3/includes/Setup.php
@@ -122,7 +122,15 @@
123123 $wgMemc->set_debug( $wgMemCachedDebug );
124124
125125 $messageMemc = &$wgMemc;
 126+} elseif ( $wgUseTurckShm ) {
 127+ # Turck shared memory
 128+ #
 129+ require_once( 'ObjectCache.php' );
 130+ $wgMemc = new TurckBagOStuff;
 131+ $messageMemc = &$wgMemc;
126132 } else {
 133+ # No shared memory
 134+ #
127135 class FakeMemCachedClient {
128136 function add ($key, $val, $exp = 0) { return true; }
129137 function decr ($key, $amt=1) { return null; }

Status & tagging log

  • 01:56, 13 October 2010 ^demon (Talk | contribs) changed the status of r4882 [removed: new added: old]
Personal tools
Namespaces

Variants
Views
Actions
Navigation
Support
Download
Development
Communication
Toolbox