Index: trunk/phase3/includes/MessageCache.php |
— | — | @@ -21,15 +21,18 @@ |
22 | 22 | // Holds loaded messages that are defined in MediaWiki namespace. |
23 | 23 | var $mCache; |
24 | 24 | |
25 | | - var $mUseCache, $mDisable, $mExpiry; |
| 25 | + var $mDisable, $mExpiry; |
26 | 26 | var $mKeys, $mParserOptions, $mParser; |
27 | 27 | |
28 | 28 | // Variable for tracking which variables are loaded |
29 | 29 | var $mLoadedLanguages = array(); |
30 | 30 | |
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; |
34 | 37 | $this->mDisable = !$useDB; |
35 | 38 | $this->mExpiry = $expiry; |
36 | 39 | $this->mDisableTransform = false; |
— | — | @@ -189,10 +192,6 @@ |
190 | 193 | function load( $code = false ) { |
191 | 194 | global $wgUseLocalMessageCache; |
192 | 195 | |
193 | | - if ( !$this->mUseCache ) { |
194 | | - return true; |
195 | | - } |
196 | | - |
197 | 196 | if( !is_string( $code ) ) { |
198 | 197 | # This isn't really nice, so at least make a note about it and try to |
199 | 198 | # fall back |
— | — | @@ -458,10 +457,6 @@ |
459 | 458 | * @return Boolean: success |
460 | 459 | */ |
461 | 460 | function lock($key) { |
462 | | - if ( !$this->mUseCache ) { |
463 | | - return true; |
464 | | - } |
465 | | - |
466 | 461 | $lockKey = $key . ':lock'; |
467 | 462 | for ($i=0; $i < MSG_WAIT_TIMEOUT && !$this->mMemc->add( $lockKey, 1, MSG_LOCK_TIMEOUT ); $i++ ) { |
468 | 463 | sleep(1); |
— | — | @@ -471,10 +466,6 @@ |
472 | 467 | } |
473 | 468 | |
474 | 469 | function unlock($key) { |
475 | | - if ( !$this->mUseCache ) { |
476 | | - return; |
477 | | - } |
478 | | - |
479 | 470 | $lockKey = $key . ':lock'; |
480 | 471 | $this->mMemc->delete( $lockKey ); |
481 | 472 | } |
— | — | @@ -590,14 +581,12 @@ |
591 | 582 | $type = false; |
592 | 583 | $message = false; |
593 | 584 | |
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 ); |
602 | 591 | } |
603 | 592 | } |
604 | 593 | |
— | — | @@ -615,23 +604,20 @@ |
616 | 605 | $titleKey = wfMemcKey( 'messages', 'individual', $title ); |
617 | 606 | |
618 | 607 | # 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 ); |
623 | 611 | |
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 ); |
636 | 622 | } |
637 | 623 | } |
638 | 624 | |
— | — | @@ -639,10 +625,8 @@ |
640 | 626 | $revision = Revision::newFromTitle( Title::makeTitle( NS_MEDIAWIKI, $title ) ); |
641 | 627 | if( $revision ) { |
642 | 628 | $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 ); |
647 | 631 | } else { |
648 | 632 | # Negative caching |
649 | 633 | # Use some special text instead of false, because false gets converted to '' somewhere |
— | — | @@ -703,14 +687,12 @@ |
704 | 688 | * Clear all stored messages. Mainly used after a mass rebuild. |
705 | 689 | */ |
706 | 690 | 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' ) ); |
715 | 697 | } |
716 | 698 | } |
717 | 699 | |