Make ObjectCache check the value of apc.enable_cli in CLI mode
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 28 Aug 2019 14:23:19 +0000 (07:23 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 29 Aug 2019 16:04:18 +0000 (09:04 -0700)
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
includes/objectcache/ObjectCache.php

index 80eb2f7..1803009 100644 (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;
index ad0f67e..f1a96c8 100644 (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;
        }
 }