objectcache: Move main cache to internal "_LocalClusterCache" service
This is preparation for re-using it in the MainWANObjectCache service in a way that preserves proper dependency injection. This is related to a declined task (T243233) which proposed offering it as a non-internal service. It is expected to remain internal, with public callers generally migrated to WANObjectCache or WRStats or in some cases to a (not yet implemented) lock manager service. Bug: T329680 Change-Id: I8af9667529b4896f17a22b66823e7eac859d4229
This commit is contained in:
parent
bf34238252
commit
d16eba24df
4 changed files with 27 additions and 17 deletions
|
|
@ -2325,6 +2325,18 @@ return [
|
|||
);
|
||||
},
|
||||
|
||||
'_LocalClusterCache' => static function ( MediaWikiServices $services ): BagOStuff {
|
||||
$mainConfig = $services->getMainConfig();
|
||||
$id = $mainConfig->get( MainConfigNames::MainCacheType );
|
||||
$params = $mainConfig->get( MainConfigNames::ObjectCaches )[$id] ?? null;
|
||||
if ( !$params ) {
|
||||
throw new UnexpectedValueException(
|
||||
"\$wgObjectCaches must have \"$id\" set (via \$wgMainCacheType)"
|
||||
);
|
||||
}
|
||||
return ObjectCache::newFromParams( $params, $services );
|
||||
},
|
||||
|
||||
'_MediaWikiTitleCodec' => static function ( MediaWikiServices $services ): MediaWikiTitleCodec {
|
||||
return new MediaWikiTitleCodec(
|
||||
$services->getContentLanguage(),
|
||||
|
|
|
|||
|
|
@ -298,9 +298,7 @@ class ObjectCache {
|
|||
* @return BagOStuff
|
||||
*/
|
||||
public static function getLocalClusterInstance() {
|
||||
global $wgMainCacheType;
|
||||
|
||||
return self::getInstance( $wgMainCacheType );
|
||||
return MediaWikiServices::getInstance()->get( '_LocalClusterCache' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -891,23 +891,25 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
|
|||
*
|
||||
* @note This will cause any existing service instances to be reset.
|
||||
*
|
||||
* @param string|BagOStuff $cache
|
||||
*
|
||||
* @param string|int|BagOStuff $cache
|
||||
* @return string|int The new value of the MainCacheType setting.
|
||||
*/
|
||||
protected function setMainCache( $cache ) {
|
||||
if ( $cache instanceof BagOStuff ) {
|
||||
// ObjectCache::$instances is reset after each test by resetNonGlobalServices().
|
||||
ObjectCache::$instances[ 'UTCache' ] = $cache;
|
||||
$cache = 'UTCache';
|
||||
$cacheId = 'UTCache';
|
||||
ObjectCache::$instances[ $cacheId ] = $cache;
|
||||
} else {
|
||||
$cacheId = $cache;
|
||||
$cache = ObjectCache::getInstance( $cacheId );
|
||||
}
|
||||
|
||||
if ( !is_string( $cache ) && !is_int( $cache ) ) {
|
||||
throw new InvalidArgumentException( 'Bad type of $cache parameter: ' . get_debug_type( $cache ) );
|
||||
if ( !is_string( $cacheId ) && !is_int( $cacheId ) ) {
|
||||
throw new InvalidArgumentException( 'Bad type of $cache parameter: ' . get_debug_type( $cacheId ) );
|
||||
}
|
||||
|
||||
$this->overrideConfigValue( MainConfigNames::MainCacheType, $cache );
|
||||
return $cache;
|
||||
$this->overrideConfigValue( MainConfigNames::MainCacheType, $cacheId );
|
||||
$this->setService( '_LocalClusterCache', $cache );
|
||||
return $cacheId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -62,12 +62,11 @@ class ObjectCacheTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
public function testNewAnythingNoAccel() {
|
||||
$this->setMainCache( CACHE_ACCEL );
|
||||
|
||||
// Mock APC not being installed (T160519, T147161)
|
||||
$this->setCacheConfig( [
|
||||
// Mock APC not being installed (T160519, T147161)
|
||||
CACHE_ACCEL => [ 'class' => EmptyBagOStuff::class ]
|
||||
] );
|
||||
$this->setMainCache( CACHE_ACCEL );
|
||||
|
||||
$this->assertInstanceOf(
|
||||
SqlBagOStuff::class,
|
||||
|
|
@ -77,12 +76,11 @@ class ObjectCacheTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
public function testNewAnythingNoAccelNoDb() {
|
||||
$this->setMainCache( CACHE_ACCEL );
|
||||
|
||||
$this->setCacheConfig( [
|
||||
// Mock APC not being installed (T160519, T147161)
|
||||
CACHE_ACCEL => [ 'class' => EmptyBagOStuff::class ]
|
||||
] );
|
||||
$this->setMainCache( CACHE_ACCEL );
|
||||
|
||||
$this->getServiceContainer()->disableStorage();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue