* Use local cache as well, this might be called a lot in certain circumstances
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Sat, 10 May 2008 12:55:59 +0000 (12:55 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Sat, 10 May 2008 12:55:59 +0000 (12:55 +0000)
languages/Language.php

index 8738141..b8d2aec 100644 (file)
@@ -2183,21 +2183,35 @@ class Language {
         * Get the fallback for a given language
         */
        static function getFallbackFor( $code ) {
+               // Shortcut
                if ( $code === 'en' ) return false;
 
+               // Local cache
+               static $cache = array();
+               // Quick return
+               if ( isset($cache[$code]) ) return $cache[$code];
+
+               // Try memcache
                global $wgMemc;
                $memcKey = wfMemcKey( 'fallback', $code );
                $fbcode = $wgMemc->get( $memcKey );
 
                if ( is_string($fbcode) ) {
-                       wfDebug( __METHOD__ . ": got fallback for $code from memc: '$fbcode'\n" );
+                       // False is stored as a string to detect failures in memcache properly
                        if ( $fbcode === '' ) $fbcode = false;
+
+                       // Update local cache and return
+                       $cache[$code] = $fbcode;
                        return $fbcode;
                }
-               
+
+               // Nothing in caches, load and and update both caches
                self::loadLocalisation( $code );
                $fbcode = self::$mLocalisationCache[$code]['fallback'];
+
+               $cache[$code] = $fbcode;
                $wgMemc->set( $memcKey, (string) $fbcode );
+
                return $fbcode;
        }