r70514 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70513‎ | r70514 | r70515 >
Date:18:19, 5 August 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Simplify MessageCache by removing mUseCache

Instead, make sure mMemc is always valid
Modified paths:
  • /trunk/phase3/includes/MessageCache.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/MessageCache.php
@@ -21,15 +21,18 @@
2222 // Holds loaded messages that are defined in MediaWiki namespace.
2323 var $mCache;
2424
25 - var $mUseCache, $mDisable, $mExpiry;
 25+ var $mDisable, $mExpiry;
2626 var $mKeys, $mParserOptions, $mParser;
2727
2828 // Variable for tracking which variables are loaded
2929 var $mLoadedLanguages = array();
3030
31 - function __construct( &$memCached, $useDB, $expiry, /*ignored*/ $memcPrefix ) {
32 - $this->mUseCache = !is_null( $memCached );
33 - $this->mMemc = &$memCached;
 31+ function __construct( $memCached, $useDB, $expiry, /*ignored*/ $memcPrefix ) {
 32+ if ( !$memCached ) {
 33+ $memCached = wfGetCache( CACHE_NONE );
 34+ }
 35+
 36+ $this->mMemc = $memCached;
3437 $this->mDisable = !$useDB;
3538 $this->mExpiry = $expiry;
3639 $this->mDisableTransform = false;
@@ -189,10 +192,6 @@
190193 function load( $code = false ) {
191194 global $wgUseLocalMessageCache;
192195
193 - if ( !$this->mUseCache ) {
194 - return true;
195 - }
196 -
197196 if( !is_string( $code ) ) {
198197 # This isn't really nice, so at least make a note about it and try to
199198 # fall back
@@ -458,10 +457,6 @@
459458 * @return Boolean: success
460459 */
461460 function lock($key) {
462 - if ( !$this->mUseCache ) {
463 - return true;
464 - }
465 -
466461 $lockKey = $key . ':lock';
467462 for ($i=0; $i < MSG_WAIT_TIMEOUT && !$this->mMemc->add( $lockKey, 1, MSG_LOCK_TIMEOUT ); $i++ ) {
468463 sleep(1);
@@ -471,10 +466,6 @@
472467 }
473468
474469 function unlock($key) {
475 - if ( !$this->mUseCache ) {
476 - return;
477 - }
478 -
479470 $lockKey = $key . ':lock';
480471 $this->mMemc->delete( $lockKey );
481472 }
@@ -590,14 +581,12 @@
591582 $type = false;
592583 $message = false;
593584
594 - if ( $this->mUseCache ) {
595 - $this->load( $code );
596 - if (isset( $this->mCache[$code][$title] ) ) {
597 - $entry = $this->mCache[$code][$title];
598 - $type = substr( $entry, 0, 1 );
599 - if ( $type == ' ' ) {
600 - return substr( $entry, 1 );
601 - }
 585+ $this->load( $code );
 586+ if (isset( $this->mCache[$code][$title] ) ) {
 587+ $entry = $this->mCache[$code][$title];
 588+ $type = substr( $entry, 0, 1 );
 589+ if ( $type == ' ' ) {
 590+ return substr( $entry, 1 );
602591 }
603592 }
604593
@@ -615,23 +604,20 @@
616605 $titleKey = wfMemcKey( 'messages', 'individual', $title );
617606
618607 # Try the individual message cache
619 - if ( $this->mUseCache ) {
620 - $entry = $this->mMemc->get( $titleKey );
621 - if ( $entry ) {
622 - $type = substr( $entry, 0, 1 );
 608+ $entry = $this->mMemc->get( $titleKey );
 609+ if ( $entry ) {
 610+ $type = substr( $entry, 0, 1 );
623611
624 - if ( $type === ' ' ) {
625 - # Ok!
626 - $message = substr( $entry, 1 );
627 - $this->mCache[$code][$title] = $entry;
628 - return $message;
629 - } elseif ( $entry === '!NONEXISTENT' ) {
630 - return false;
631 - } else {
632 - # Corrupt/obsolete entry, delete it
633 - $this->mMemc->delete( $titleKey );
634 - }
635 -
 612+ if ( $type === ' ' ) {
 613+ # Ok!
 614+ $message = substr( $entry, 1 );
 615+ $this->mCache[$code][$title] = $entry;
 616+ return $message;
 617+ } elseif ( $entry === '!NONEXISTENT' ) {
 618+ return false;
 619+ } else {
 620+ # Corrupt/obsolete entry, delete it
 621+ $this->mMemc->delete( $titleKey );
636622 }
637623 }
638624
@@ -639,10 +625,8 @@
640626 $revision = Revision::newFromTitle( Title::makeTitle( NS_MEDIAWIKI, $title ) );
641627 if( $revision ) {
642628 $message = $revision->getText();
643 - if ($this->mUseCache) {
644 - $this->mCache[$code][$title] = ' ' . $message;
645 - $this->mMemc->set( $titleKey, ' ' . $message, $this->mExpiry );
646 - }
 629+ $this->mCache[$code][$title] = ' ' . $message;
 630+ $this->mMemc->set( $titleKey, ' ' . $message, $this->mExpiry );
647631 } else {
648632 # Negative caching
649633 # Use some special text instead of false, because false gets converted to '' somewhere
@@ -703,14 +687,12 @@
704688 * Clear all stored messages. Mainly used after a mass rebuild.
705689 */
706690 function clear() {
707 - if( $this->mUseCache ) {
708 - $langs = Language::getLanguageNames( false );
709 - foreach ( array_keys($langs) as $code ) {
710 - # Global cache
711 - $this->mMemc->delete( wfMemcKey( 'messages', $code ) );
712 - # Invalidate all local caches
713 - $this->mMemc->delete( wfMemcKey( 'messages', $code, 'hash' ) );
714 - }
 691+ $langs = Language::getLanguageNames( false );
 692+ foreach ( array_keys($langs) as $code ) {
 693+ # Global cache
 694+ $this->mMemc->delete( wfMemcKey( 'messages', $code ) );
 695+ # Invalidate all local caches
 696+ $this->mMemc->delete( wfMemcKey( 'messages', $code, 'hash' ) );
715697 }
716698 }
717699

Status & tagging log