(Bug 38439) Attempt on fixing the suicidal LangObjCache

This replaces the suicide of LangObjCache and replaces it with a
LRU of configurable length.

The patch seems to be functional when I dumped some debug info.

Patchset 2: Updated commit message, reformatted a few lines.
Patchset 3: Removed the "do not merge"

Change-Id: Iee2c796a0c4dd491e31425e04121a1bf0554d7c9
This commit is contained in:
jeblad 2012-11-26 00:01:24 +01:00
parent 289c407957
commit 121cf60119
2 changed files with 20 additions and 9 deletions

View file

@ -2165,6 +2165,12 @@ $wgUsePrivateIPs = false;
/** Site language code, should be one of ./languages/Language(.*).php */
$wgLanguageCode = 'en';
/**
* Language cache size, or really how many languages can we handle
* simultanously without degrading to crawl speed.
*/
$wgLangObjCacheSize = 10;
/**
* Some languages need different word forms, usually for different cases.
* Used in Language::convertGrammar().

View file

@ -172,19 +172,24 @@ class Language {
);
/**
* Get a cached language object for a given language code
* Get a cached or new language object for a given language code
* @param $code String
* @return Language
*/
static function factory( $code ) {
if ( !isset( self::$mLangObjCache[$code] ) ) {
if ( count( self::$mLangObjCache ) > 10 ) {
// Don't keep a billion objects around, that's stupid.
self::$mLangObjCache = array();
}
self::$mLangObjCache[$code] = self::newFromCode( $code );
}
return self::$mLangObjCache[$code];
global $wgLangObjCacheSize;
// get the language object to process
$langObj = isset( self::$mLangObjCache[$code] )
? self::$mLangObjCache[$code]
: self::newFromCode( $code );
// merge the language object in to get it up front in the cache
self::$mLangObjCache = array_merge( array( $code => $langObj ), self::$mLangObjCache );
// get rid of the oldest ones in case we have an overflow
self::$mLangObjCache = array_slice( self::$mLangObjCache, 0, $wgLangObjCacheSize, true );
return $langObj;
}
/**