From 1b57f6a81be7ac1e9e7e71b3bae0ab2d8fc94a5d Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 28 Aug 2019 07:23:19 -0700 Subject: [PATCH] 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 --- includes/db/MWLBFactory.php | 11 ++++++++--- includes/objectcache/ObjectCache.php | 11 +++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/includes/db/MWLBFactory.php b/includes/db/MWLBFactory.php index 80eb2f70fb..18030090df 100644 --- a/includes/db/MWLBFactory.php +++ b/includes/db/MWLBFactory.php @@ -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; diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index ad0f67e590..f1a96c8756 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -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; } } -- 2.20.1