Make ObjectCache check the value of apc.enable_cli in CLI mode

Add HashBagOStuff fallback for APC in MWLBFactory::injectObjectCaches.

Also fix APC-cache variable typo in MWLBFactory.

Bug: T227838
Change-Id: I71cb2ca58972ea09ab2f64f7e47bda7a5096c19b
This commit is contained in:
Aaron Schulz 2019-08-28 07:23:19 -07:00
parent 48c8531c2e
commit 1b57f6a81b
2 changed files with 17 additions and 5 deletions

View file

@ -66,7 +66,7 @@ abstract class MWLBFactory {
* @param array $lbConf Config for LBFactory::__construct()
* @param ServiceOptions $options
* @param ConfiguredReadOnlyMode $readOnlyMode
* @param BagOStuff $srvCace
* @param BagOStuff $srvCache
* @param BagOStuff $mainStash
* @param WANObjectCache $wanCache
* @return array
@ -76,7 +76,7 @@ abstract class MWLBFactory {
array $lbConf,
ServiceOptions $options,
ConfiguredReadOnlyMode $readOnlyMode,
BagOStuff $srvCace,
BagOStuff $srvCache,
BagOStuff $mainStash,
WANObjectCache $wanCache
) {
@ -159,7 +159,7 @@ abstract class MWLBFactory {
$options->get( 'DBprefix' )
);
$lbConf = self::injectObjectCaches( $lbConf, $srvCace, $mainStash, $wanCache );
$lbConf = self::injectObjectCaches( $lbConf, $srvCache, $mainStash, $wanCache );
return $lbConf;
}
@ -222,6 +222,11 @@ abstract class MWLBFactory {
private static function injectObjectCaches(
array $lbConf, BagOStuff $sCache, BagOStuff $mStash, WANObjectCache $wCache
) {
// Fallback if APC style caching is not an option
if ( $sCache instanceof EmptyBagOStuff ) {
$sCache = new HashBagOStuff( [ 'maxKeys' => 100 ] );
}
// Use APC/memcached style caching, but avoids loops with CACHE_DB (T141804)
if ( $sCache->getQoS( $sCache::ATTR_EMULATION ) > $sCache::QOS_EMULATION_SQL ) {
$lbConf['srvCache'] = $sCache;

View file

@ -393,12 +393,19 @@ class ObjectCache {
*/
public static function detectLocalServerCache() {
if ( function_exists( 'apcu_fetch' ) ) {
return 'apcu';
// Make sure the APCu methods actually store anything
if ( PHP_SAPI !== 'cli' || ini_get( 'apc.enable_cli' ) ) {
return 'apcu';
}
} elseif ( function_exists( 'apc_fetch' ) ) {
return 'apc';
// Make sure the APC methods actually store anything
if ( PHP_SAPI !== 'cli' || ini_get( 'apc.enable_cli' ) ) {
return 'apc';
}
} elseif ( function_exists( 'wincache_ucache_get' ) ) {
return 'wincache';
}
return CACHE_NONE;
}
}