diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index f97d60df028..ee92cbfecf3 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -404,24 +404,8 @@ return [ }, 'LocalServerObjectCache' => function ( MediaWikiServices $services ) { - $mainConfig = $services->getMainConfig(); - - if ( function_exists( 'apc_fetch' ) ) { - $id = 'apc'; - } elseif ( function_exists( 'apcu_fetch' ) ) { - $id = 'apcu'; - } elseif ( function_exists( 'wincache_ucache_get' ) ) { - $id = 'wincache'; - } else { - $id = CACHE_NONE; - } - - if ( !isset( $mainConfig->get( 'ObjectCaches' )[$id] ) ) { - throw new UnexpectedValueException( - "Cache type \"$id\" is not present in \$wgObjectCaches." ); - } - - return \ObjectCache::newFromParams( $mainConfig->get( 'ObjectCaches' )[$id] ); + $cacheId = \ObjectCache::detectLocalServerCache(); + return \ObjectCache::newFromId( $cacheId ); }, 'VirtualRESTServiceClient' => function ( MediaWikiServices $services ) { diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index a6f55e60261..c3840322202 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -413,4 +413,21 @@ class ObjectCache { self::$instances = []; self::$wanInstances = []; } + + /** + * Detects which local server cache library is present and returns a configuration for it + * @since 1.32 + * + * @return int|string Index to cache in $wgObjectCaches + */ + public static function detectLocalServerCache() { + if ( function_exists( 'apc_fetch' ) ) { + return 'apc'; + } elseif ( function_exists( 'apcu_fetch' ) ) { + return 'apcu'; + } elseif ( function_exists( 'wincache_ucache_get' ) ) { + return 'wincache'; + } + return CACHE_NONE; + } } diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php index b000dc11b10..b34a1236352 100644 --- a/includes/registration/ExtensionRegistry.php +++ b/includes/registration/ExtensionRegistry.php @@ -1,7 +1,5 @@ getLocalServerObjectCache(); + // Don't use MediaWikiServices here to prevent instantiating it before extensions have + // been loaded + $cacheId = ObjectCache::detectLocalServerCache(); + $cache = ObjectCache::newFromId( $cacheId ); } catch ( MWException $e ) { $cache = new EmptyBagOStuff(); }