r112691 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112690‎ | r112691 | r112692 >
Date:14:44, 29 February 2012
Author:nikerabbit
Status:ok
Tags:
Comment:
Don't rely on wgMemc being real cache
Modified paths:
  • /trunk/extensions/Translate/utils/TranslationHelpers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/utils/TranslationHelpers.php
@@ -449,8 +449,6 @@
450450 }
451451
452452 protected function getMicrosoftSuggestion( $serviceName, $config ) {
453 - global $wgMemc;
454 -
455453 $this->mustHaveDefinition();
456454 self::checkTranslationServiceFailure( $serviceName );
457455
@@ -459,7 +457,7 @@
460458 $definition = self::wrapUntranslatable( $definition );
461459
462460 $memckey = wfMemckey( 'translate-tmsug-badcodes-' . $serviceName );
463 - $unsupported = $wgMemc->get( $memckey );
 461+ $unsupported = wfGetCache( CACHE_ANYTHING )->get( $memckey );
464462
465463 if ( isset( $unsupported[$code] ) ) {
466464 return null;
@@ -496,7 +494,7 @@
497495 $error = $req->getContent();
498496 if ( strpos( $error, 'must be a valid language' ) !== false ) {
499497 $unsupported[$code] = true;
500 - $wgMemc->set( $memckey, $unsupported, 60 * 60 * 8 );
 498+ wfGetCache( CACHE_ANYTHING )->set( $memckey, $unsupported, 60 * 60 * 8 );
501499 return null;
502500 }
503501
@@ -531,8 +529,6 @@
532530 }
533531
534532 protected function getApertiumSuggestion( $serviceName, $config ) {
535 - global $wgMemc;
536 -
537533 self::checkTranslationServiceFailure( $serviceName );
538534
539535 $page = $this->handle->getKey();
@@ -540,7 +536,7 @@
541537 $ns = $this->handle->getTitle()->getNamespace();
542538
543539 $memckey = wfMemckey( 'translate-tmsug-pairs-' . $serviceName );
544 - $pairs = $wgMemc->get( $memckey );
 540+ $pairs = wfGetCache( CACHE_ANYTHING )->get( $memckey );
545541
546542 if ( !$pairs ) {
547543
@@ -564,7 +560,7 @@
565561 $pairs[$target][$source] = true;
566562 }
567563
568 - $wgMemc->set( $memckey, $pairs, 60 * 60 * 24 );
 564+ wfGetCache( CACHE_ANYTHING )->set( $memckey, $pairs, 60 * 60 * 24 );
569565 }
570566
571567 if ( isset( $config['codemap'][$code] ) ) {
@@ -1258,10 +1254,8 @@
12591255 * @return bool
12601256 */
12611257 public static function checkTranslationServiceFailure( $service ) {
1262 - global $wgMemc;
1263 -
12641258 $key = wfMemckey( "translate-service-$service" );
1265 - $value = $wgMemc->get( $key );
 1259+ $value = wfGetCache( CACHE_ANYTHING )->get( $key );
12661260 if ( !is_string( $value ) ) {
12671261 return false;
12681262 }
@@ -1271,7 +1265,7 @@
12721266 if ( $count >= self::$serviceFailureCount ) {
12731267 error_log( "Translation service $service (was) restored" );
12741268 }
1275 - $wgMemc->delete( $key );
 1269+ wfGetCache( CACHE_ANYTHING )->delete( $key );
12761270 return false;
12771271 } elseif ( $failed + self::$serviceFailurePeriod < wfTimestamp() ) {
12781272 /* We are in suspicious mode and one failure is enough to update
@@ -1291,10 +1285,8 @@
12921286 * @param $service
12931287 */
12941288 public static function reportTranslationServiceFailure( $service ) {
1295 - global $wgMemc;
1296 -
12971289 $key = wfMemckey( "translate-service-$service" );
1298 - $value = $wgMemc->get( $key );
 1290+ $value = wfGetCache( CACHE_ANYTHING )->get( $key );
12991291 if ( !is_string( $value ) ) {
13001292 $count = 0;
13011293 } else {
@@ -1303,7 +1295,7 @@
13041296
13051297 $count += 1;
13061298 $failed = wfTimestamp();
1307 - $wgMemc->set( $key, "$count|$failed", self::$serviceFailurePeriod * 5 );
 1299+ wfGetCache( CACHE_ANYTHING )->set( $key, "$count|$failed", self::$serviceFailurePeriod * 5 );
13081300
13091301 if ( $count == self::$serviceFailureCount ) {
13101302 error_log( "Translation service $service suspended" );

Status & tagging log