X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fobjectcache%2FObjectCache.php;h=53a474b6e35e7770879586297e4701490ef85455;hb=5c59e46a72e876d5d409d994328217b2164a2f1d;hp=14809a87e2551fa88dccbd1363b5fa497900dcc6;hpb=ae4a435159c3f234028c27a7247b407b9f37ad13;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index 14809a87e2..53a474b6e3 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -50,7 +50,7 @@ use MediaWiki\MediaWikiServices; * * - ObjectCache::getLocalServerInstance( $fallbackType ) * Purpose: Memory cache for very hot keys. - * Stored only on the individual web server (typically APC for web requests, + * Stored only on the individual web server (typically APC or APCu for web requests, * and EmptyBagOStuff in CLI mode). * Not replicated to the other servers. * @@ -190,7 +190,7 @@ class ObjectCache { ? $params['reportDupes'] : true; // Do b/c logic for SqlBagOStuff - if ( is_subclass_of( $class, SqlBagOStuff::class ) ) { + if ( is_a( $class, SqlBagOStuff::class, true ) ) { if ( isset( $params['server'] ) && !isset( $params['servers'] ) ) { $params['servers'] = [ $params['server'] ]; unset( $params['server'] ); @@ -265,7 +265,7 @@ class ObjectCache { /** * Factory function for CACHE_ACCEL (referenced from DefaultSettings.php) * - * This will look for any APC style server-local cache. + * This will look for any APC or APCu style server-local cache. * A fallback cache can be specified if none is found. * * // Direct calls @@ -280,39 +280,15 @@ class ObjectCache { * @since 1.27 */ public static function getLocalServerInstance( $fallback = CACHE_NONE ) { - if ( function_exists( 'apc_fetch' ) ) { - $id = 'apc'; - } elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) { - $id = 'xcache'; - } elseif ( function_exists( 'wincache_ucache_get' ) ) { - $id = 'wincache'; - } else { + $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache(); + if ( $cache instanceof EmptyBagOStuff ) { if ( is_array( $fallback ) ) { - $id = isset( $fallback['fallback'] ) ? $fallback['fallback'] : CACHE_NONE; - } else { - $id = $fallback; - } - } - - return self::getInstance( $id ); - } - - /** - * @param array $params [optional] Array key 'fallback' for $fallback. - * @param int|string $fallback Fallback cache, e.g. (CACHE_NONE, "hash") (since 1.24) - * @return BagOStuff - * @deprecated since 1.27 - */ - public static function newAccelerator( $params = [], $fallback = null ) { - if ( $fallback === null ) { - if ( is_array( $params ) && isset( $params['fallback'] ) ) { - $fallback = $params['fallback']; - } elseif ( !is_array( $params ) ) { - $fallback = $params; + $fallback = isset( $fallback['fallback'] ) ? $fallback['fallback'] : CACHE_NONE; } + $cache = self::getInstance( $fallback ); } - return self::getLocalServerInstance( $fallback ); + return $cache; } /** @@ -321,23 +297,41 @@ class ObjectCache { * @since 1.26 * @param string $id A key in $wgWANObjectCaches. * @return WANObjectCache - * @throws InvalidArgumentException + * @throws UnexpectedValueException */ public static function newWANCacheFromId( $id ) { - global $wgWANObjectCaches; + global $wgWANObjectCaches, $wgObjectCaches; if ( !isset( $wgWANObjectCaches[$id] ) ) { - throw new InvalidArgumentException( "Invalid object cache type \"$id\" requested. " . - "It is not present in \$wgWANObjectCaches." ); + throw new UnexpectedValueException( + "Cache type \"$id\" requested is not present in \$wgWANObjectCaches." ); } $params = $wgWANObjectCaches[$id]; + if ( !isset( $wgObjectCaches[$params['cacheId']] ) ) { + throw new UnexpectedValueException( + "Cache type \"{$params['cacheId']}\" is not present in \$wgObjectCaches." ); + } + $params['store'] = $wgObjectCaches[$params['cacheId']]; + + return self::newWANCacheFromParams( $params ); + } + + /** + * Create a new cache object of the specified type. + * + * @since 1.28 + * @param array $params + * @return WANObjectCache + * @throws UnexpectedValueException + */ + public static function newWANCacheFromParams( array $params ) { foreach ( $params['channels'] as $action => $channel ) { $params['relayers'][$action] = MediaWikiServices::getInstance()->getEventRelayerGroup() ->getRelayer( $channel ); $params['channels'][$action] = $channel; } - $params['cache'] = self::newFromId( $params['cacheId'] ); + $params['cache'] = self::newFromParams( $params['store'] ); if ( isset( $params['loggroup'] ) ) { $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] ); } else { @@ -365,11 +359,10 @@ class ObjectCache { * * @since 1.26 * @return WANObjectCache + * @deprecated Since 1.28 Use MediaWikiServices::getMainWANCache() */ public static function getMainWANInstance() { - global $wgMainWANCache; - - return self::getWANInstance( $wgMainWANCache ); + return MediaWikiServices::getInstance()->getMainWANObjectCache(); } /** @@ -389,11 +382,10 @@ class ObjectCache { * * @return BagOStuff * @since 1.26 + * @deprecated Since 1.28 Use MediaWikiServices::getMainObjectStash */ public static function getMainStashInstance() { - global $wgMainStash; - - return self::getInstance( $wgMainStash ); + return MediaWikiServices::getInstance()->getMainObjectStash(); } /**