objectcache: Add makeLocalServerCache() method
This bypasses the indirection of global wgObjectCaches config and ObjectCache::newFromParams static methods, which don't do anything in practice. This solves the ExtensionRegistry use-case where it couldn't use the service container, which in turn opens the path for being able to deprecate absence of Config being passed to ObjectCache::newFromParams(), which isn't possible right now because ExtensionRegistry depended on being able to call it without that, and that is a hard requirement because ExtensionRegistry isn't allowed to use the service container. Change-Id: Ic88da279662f33d3585cb2232358d6faf590b5b3
This commit is contained in:
parent
8d4aaa43cb
commit
746d67f5fc
4 changed files with 40 additions and 21 deletions
|
|
@ -464,8 +464,11 @@ because of Phabricator reports.
|
|||
- protected $handler (not need anymore)
|
||||
- cleanupHandlersCache (not need anymore)
|
||||
* (T212738) The $wgVersion global is deprecated; instead, use MW_VERSION.
|
||||
* $wgMemc is deprecated, use
|
||||
MediaWikiServices::getInstance()->getLocalServerObjectCache() instead.
|
||||
* $wgMemc is deprecated, use MediaWikiServices::getLocalServerObjectCache()
|
||||
instead.
|
||||
* ObjectCache::detectLocalServerCache() is deprecated, instead use
|
||||
MediaWikiServices::getLocalServerObjectCache() or
|
||||
ObjectCache::makeLocalServerCache().
|
||||
* ImagePage::getImageLimitsFromOptions() is deprecated. Use static function
|
||||
MediaFileTrait::getImageLimitsFromOptions() instead.
|
||||
* A number of Parser-related methods were deprecated to simplify the API or
|
||||
|
|
|
|||
|
|
@ -467,10 +467,7 @@ return [
|
|||
},
|
||||
|
||||
'LocalServerObjectCache' => function ( MediaWikiServices $services ) : BagOStuff {
|
||||
$config = $services->getMainConfig();
|
||||
$cacheId = ObjectCache::detectLocalServerCache();
|
||||
|
||||
return ObjectCache::newFromParams( $config->get( 'ObjectCaches' )[$cacheId], $config );
|
||||
return ObjectCache::makeLocalServerCache();
|
||||
},
|
||||
|
||||
'LockManagerGroupFactory' => function ( MediaWikiServices $services ) : LockManagerGroupFactory {
|
||||
|
|
|
|||
|
|
@ -291,12 +291,40 @@ class ObjectCache {
|
|||
}
|
||||
|
||||
/**
|
||||
* Detects which local server cache library is present and returns a configuration for it
|
||||
* @since 1.32
|
||||
* Create a new BagOStuff instance for local-server caching.
|
||||
*
|
||||
* Only use this if you explicitly require the creation of
|
||||
* a fresh instance. Whenever possible, use or inject the object
|
||||
* from MediaWikiServices::getLocalServerObjectCache() instead.
|
||||
*
|
||||
* @since 1.35
|
||||
* @return BagOStuff
|
||||
*/
|
||||
public static function makeLocalServerCache() : BagOStuff {
|
||||
$params = [ 'reportDupes' => false ];
|
||||
if ( function_exists( 'apcu_fetch' ) ) {
|
||||
// Make sure the APCu methods actually store anything
|
||||
if ( PHP_SAPI !== 'cli' || ini_get( 'apc.enable_cli' ) ) {
|
||||
return new APCUBagOStuff( $params );
|
||||
}
|
||||
} elseif ( function_exists( 'wincache_ucache_get' ) ) {
|
||||
return new WinCacheBagOStuff( $params );
|
||||
}
|
||||
|
||||
return new EmptyBagOStuff( $params );
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects which local server cache library is present and returns a configuration for it.
|
||||
*
|
||||
* @since 1.32
|
||||
* @deprecated since 1.35 Use MediaWikiServices::getLocalServerObjectCache() or
|
||||
* ObjectCache::makeLocalServerCache() instead.
|
||||
* @return int|string Index to cache in $wgObjectCaches
|
||||
*/
|
||||
public static function detectLocalServerCache() {
|
||||
wfDeprecated( __METHOD__, '1.35' );
|
||||
|
||||
if ( function_exists( 'apcu_fetch' ) ) {
|
||||
// Make sure the APCu methods actually store anything
|
||||
if ( PHP_SAPI !== 'cli' || ini_get( 'apc.enable_cli' ) ) {
|
||||
|
|
|
|||
|
|
@ -175,19 +175,10 @@ class ExtensionRegistry {
|
|||
$this->queued[$path] = $mtime;
|
||||
}
|
||||
|
||||
private function getCache(): BagOStuff {
|
||||
global $wgObjectCaches;
|
||||
// We use a try/catch because we don't want to fail here
|
||||
// if $wgObjectCaches is not configured properly for APC setup
|
||||
try {
|
||||
// Avoid MediaWikiServices to prevent instantiating it before extensions have loaded
|
||||
$cacheId = ObjectCache::detectLocalServerCache();
|
||||
return ObjectCache::newFromParams( $wgObjectCaches[$cacheId] );
|
||||
} catch ( InvalidArgumentException $e ) {
|
||||
// @codeCoverageIgnoreStart
|
||||
return new EmptyBagOStuff();
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
private function getCache() : BagOStuff {
|
||||
// Can't call MediaWikiServices here, as we must not cause services
|
||||
// to be instantiated before extensions have loaded.
|
||||
return ObjectCache::makeLocalServerCache();
|
||||
}
|
||||
|
||||
private function makeCacheKey( BagOStuff $cache, $component, ...$extra ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue