objectcache: make newFromId()/newWANcacheFromId()/getDefaultKeyspace() private
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 13 Aug 2019 00:46:14 +0000 (17:46 -0700)
committerKrinkle <krinklemail@gmail.com>
Tue, 20 Aug 2019 13:11:27 +0000 (13:11 +0000)
Change-Id: I30b99f23dbd9637ca8178d3a3650b4c38ec43e7d

includes/ServiceWiring.php
includes/objectcache/ObjectCache.php
includes/registration/ExtensionRegistry.php
tests/phpunit/includes/libs/objectcache/BagOStuffTest.php

index c192b5a..0041f42 100644 (file)
@@ -267,9 +267,10 @@ return [
        },
 
        'LocalServerObjectCache' => function ( MediaWikiServices $services ) : BagOStuff {
+               $config = $services->getMainConfig();
                $cacheId = \ObjectCache::detectLocalServerCache();
 
-               return \ObjectCache::newFromId( $cacheId );
+               return \ObjectCache::newFromParams( $config->get( 'ObjectCaches' )[$cacheId] );
        },
 
        'MagicWordFactory' => function ( MediaWikiServices $services ) : MagicWordFactory {
index 3bb0771..ad0f67e 100644 (file)
@@ -119,7 +119,7 @@ class ObjectCache {
         * @return BagOStuff
         * @throws InvalidArgumentException
         */
-       public static function newFromId( $id ) {
+       private static function newFromId( $id ) {
                global $wgObjectCaches;
 
                if ( !isset( $wgObjectCaches[$id] ) ) {
@@ -146,7 +146,7 @@ class ObjectCache {
         *
         * @return string
         */
-       public static function getDefaultKeyspace() {
+       private static function getDefaultKeyspace() {
                global $wgCachePrefix;
 
                $keyspace = $wgCachePrefix;
@@ -297,7 +297,7 @@ class ObjectCache {
         * @return WANObjectCache
         * @throws UnexpectedValueException
         */
-       public static function newWANCacheFromId( $id ) {
+       private static function newWANCacheFromId( $id ) {
                global $wgWANObjectCaches, $wgObjectCaches;
 
                if ( !isset( $wgWANObjectCaches[$id] ) ) {
index 9cae73c..3e65f6c 100644 (file)
@@ -146,7 +146,7 @@ class ExtensionRegistry {
         *  be loaded then).
         */
        public function loadFromQueue() {
-               global $wgVersion, $wgDevelopmentWarnings;
+               global $wgVersion, $wgDevelopmentWarnings, $wgObjectCaches;
                if ( !$this->queued ) {
                        return;
                }
@@ -169,10 +169,9 @@ class ExtensionRegistry {
                // We use a try/catch because we don't want to fail here
                // if $wgObjectCaches is not configured properly for APC setup
                try {
-                       // Don't use MediaWikiServices here to prevent instantiating it before extensions have
-                       // been loaded
+                       // Avoid MediaWikiServices to prevent instantiating it before extensions have loaded
                        $cacheId = ObjectCache::detectLocalServerCache();
-                       $cache = ObjectCache::newFromId( $cacheId );
+                       $cache = ObjectCache::newFromParams( $wgObjectCaches[$cacheId] );
                } catch ( InvalidArgumentException $e ) {
                        $cache = new EmptyBagOStuff();
                }
index 9ec86bc..f9176e5 100644 (file)
@@ -19,9 +19,10 @@ class BagOStuffTest extends MediaWikiTestCase {
 
                // type defined through parameter
                if ( $this->getCliArg( 'use-bagostuff' ) !== null ) {
-                       $name = $this->getCliArg( 'use-bagostuff' );
+                       global $wgObjectCaches;
 
-                       $this->cache = ObjectCache::newFromId( $name );
+                       $id = $this->getCliArg( 'use-bagostuff' );
+                       $this->cache = ObjectCache::newFromParams( $wgObjectCaches[$id] );
                } else {
                        // no type defined - use simple hash
                        $this->cache = new HashBagOStuff;
@@ -36,7 +37,7 @@ class BagOStuffTest extends MediaWikiTestCase {
         * @covers MediumSpecificBagOStuff::makeKeyInternal
         */
        public function testMakeKey() {
-               $cache = ObjectCache::newFromId( 'hash' );
+               $cache = new HashBagOStuff();
 
                $localKey = $cache->makeKey( 'first', 'second', 'third' );
                $globalKey = $cache->makeGlobalKey( 'first', 'second', 'third' );