[LanguageConverter] Added some cache code based on the problems in r97512.
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 6 Apr 2012 17:59:43 +0000 (10:59 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 6 Apr 2012 18:01:47 +0000 (11:01 -0700)
* Added $wgLanguageConverterCacheType global to control LC cache type. We can use it to enable direct apc use for language converter (to match the live hack).

Change-Id: I04616469aa53ccd1a5ce51af50a18acca5bb8bc4

includes/DefaultSettings.php
languages/LanguageConverter.php

index 8402d69..0c19810 100644 (file)
@@ -1636,6 +1636,13 @@ $wgMemCachedTimeout = 100000;
  */
 $wgUseLocalMessageCache = false;
 
+/**
+ * Make LanguageConverter use a different cache type.
+ * Possible values are false (none), 'main' ($wgMemc), and 'apc'.
+ * @since 1.20
+ */
+$wgLanguageConverterCacheType = 'main';
+
 /**
  * Defines format of local cache
  * true - Serialized object
@@ -4222,7 +4229,7 @@ $wgParserTestFiles = array(
  * );
  */
 $wgParserTestRemote = false;
+
 /**
  * Allow running of javascript test suites via [[Special:JavaScriptTest]] (such as QUnit).
  */
index 2b9cc8e..3997d7f 100644 (file)
@@ -813,13 +813,13 @@ class LanguageConverter {
                if ( $this->mTablesLoaded ) {
                        return;
                }
-               global $wgMemc;
+
                wfProfileIn( __METHOD__ );
                $this->mTablesLoaded = true;
                $this->mTables = false;
                if ( $fromCache ) {
                        wfProfileIn( __METHOD__ . '-cache' );
-                       $this->mTables = $wgMemc->get( $this->mCacheKey );
+                       $this->mTables = $this->cacheFetch( $this->mCacheKey );
                        wfProfileOut( __METHOD__ . '-cache' );
                }
                if ( !$this->mTables
@@ -837,12 +837,48 @@ class LanguageConverter {
                        $this->postLoadTables();
                        $this->mTables[self::CACHE_VERSION_KEY] = true;
 
-                       $wgMemc->set( $this->mCacheKey, $this->mTables, 43200 );
+                       $this->cacheStore( $this->mCacheKey, $this->mTables, 43200 );
                        wfProfileOut( __METHOD__ . '-recache' );
                }
                wfProfileOut( __METHOD__ );
        }
 
+       /**
+        * Read an object from the cache
+        * @param $key string
+        * @return mixed
+        */
+       protected function cacheFetch( $key ) {
+               global $wgLanguageConverterCacheType, $wgMemc;
+
+               if ( $wgLanguageConverterCacheType === 'apc' ) {
+                       return apc_fetch( $key );
+               } elseif ( $wgLanguageConverterCacheType === 'main' ) {
+                       return $wgMemc->get( $key );
+               }
+
+               return false; // disabled
+       }
+
+       /**
+        * Store an object into the cache
+        * @param $key string
+        * @param $val mixed
+        * @param $ttl integer Seconds to live
+        * @return bool Success
+        */
+       protected function cacheStore( $key, $val, $ttl ) {
+               global $wgLanguageConverterCacheType, $wgMemc;
+
+               if ( $wgLanguageConverterCacheType === 'apc' ) {
+                       return apc_store( $key, $val, $ttl );
+               } elseif ( $wgLanguageConverterCacheType === 'main' ) {
+                       return $wgMemc->set( $key, $val, $ttl );
+               }
+
+               return true; // disabled
+       }
+
        /**
         * Hook for post processing after conversion tables are loaded.
         */