objectcache: Use newAccelerator() fallback instead of try/catch
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 24 Aug 2015 20:53:16 +0000 (22:53 +0200)
committerTimo Tijhof <krinklemail@gmail.com>
Mon, 24 Aug 2015 23:03:10 +0000 (01:03 +0200)
Also remove confusing use of $wgMemc in LoadMonitorMySQL which
should always be the same as wfGetMainCache().

Change-Id: I4fb9d075a37d3d45af71a5026ccf2eb17f24d7b0

includes/db/LoadMonitorMySQL.php
includes/filebackend/SwiftFileBackend.php
includes/utils/MWCryptHKDF.php

index 752d009..3008419 100644 (file)
@@ -34,12 +34,10 @@ class LoadMonitorMySQL implements LoadMonitor {
        protected $mainCache;
 
        public function __construct( $parent ) {
-               global $wgMemc;
-
                $this->parent = $parent;
 
                $this->srvCache = ObjectCache::newAccelerator( 'hash' );
-               $this->mainCache = $wgMemc ?: wfGetMainCache();
+               $this->mainCache = wfGetMainCache();
        }
 
        public function scaleLoads( &$loads, $group = false, $wiki = false ) {
index b49c4c5..e0a08b2 100644 (file)
@@ -138,13 +138,12 @@ class SwiftFileBackend extends FileBackendStore {
                        if ( PHP_SAPI === 'cli' ) {
                                $this->srvCache = wfGetMainCache(); // preferrably memcached
                        } else {
-                               try { // look for APC, XCache, WinCache, ect...
-                                       $this->srvCache = ObjectCache::newAccelerator();
-                               } catch ( Exception $e ) {
-                               }
+                               // look for APC, XCache, WinCache, ect...
+                               $this->srvCache = ObjectCache::newAccelerator( CACHE_NONE );
                        }
+               } else {
+                       $this->srvCache = new EmptyBagOStuff();
                }
-               $this->srvCache = $this->srvCache ?: new EmptyBagOStuff();
        }
 
        public function getFeatures() {
index 1ddd119..740df92 100644 (file)
@@ -161,7 +161,7 @@ class MWCryptHKDF {
         * @throws MWException
         */
        protected static function singleton() {
-               global $wgHKDFAlgorithm, $wgHKDFSecret, $wgSecretKey;
+               global $wgHKDFAlgorithm, $wgHKDFSecret, $wgSecretKey, $wgMainCacheType;
 
                $secret = $wgHKDFSecret ?: $wgSecretKey;
                if ( !$secret ) {
@@ -176,11 +176,7 @@ class MWCryptHKDF {
                $context[] = gethostname();
 
                // Setup salt cache. Use APC, or fallback to the main cache if it isn't setup
-               try {
-                       $cache = ObjectCache::newAccelerator();
-               } catch ( Exception $e ) {
-                       $cache = wfGetMainCache();
-               }
+               $cache = ObjectCache::newAccelerator( $wgMainCacheType );
 
                if ( is_null( self::$singleton ) ) {
                        self::$singleton = new self( $secret, $wgHKDFAlgorithm, $cache, $context );