Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/250215

Change subject: Replace newAccelerator() with getLocalServerInstance()
......................................................................

Replace newAccelerator() with getLocalServerInstance()

The name is clearer and more consistent, with simpler arguments.

Change-Id: I7205a99ce033e8b086a52cd02c8a721e99c84b1e
---
M includes/DefaultSettings.php
M includes/GlobalFunctions.php
M includes/TemplateParser.php
M includes/cache/MessageCache.php
M includes/db/Database.php
M includes/db/loadbalancer/LoadMonitorMySQL.php
M includes/filebackend/SwiftFileBackend.php
M includes/filebackend/lockmanager/DBLockManager.php
M includes/media/TransformationalImageHandler.php
M includes/objectcache/ObjectCache.php
M includes/parser/DateFormatter.php
M includes/registration/ExtensionRegistry.php
M includes/resourceloader/ResourceLoader.php
M includes/resourceloader/ResourceLoaderFileModule.php
M includes/utils/FileContentsHasher.php
M includes/utils/MWCryptHKDF.php
M includes/utils/UIDGenerator.php
17 files changed, 57 insertions(+), 44 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/15/250215/1

diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index e916938..d77d195 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -2211,7 +2211,7 @@
        CACHE_DB => array( 'class' => 'SqlBagOStuff', 'loggroup' => 
'SQLBagOStuff' ),
 
        CACHE_ANYTHING => array( 'factory' => 'ObjectCache::newAnything' ),
-       CACHE_ACCEL => array( 'factory' => 'ObjectCache::newAccelerator' ),
+       CACHE_ACCEL => array( 'factory' => 
'ObjectCache::getLocalServerInstance' ),
        CACHE_MEMCACHED => array( 'class' => 'MemcachedPhpBagOStuff', 
'loggroup' => 'memcached' ),
 
        'db-replicated' => array(
diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index 791bf33..3bc3a90 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -4010,7 +4010,7 @@
                return $bad;
        }
 
-       $cache = ObjectCache::newAccelerator( 'hash' );
+       $cache = ObjectCache::getLocalServerInstance( 'hash' );
        $key = wfMemcKey( 'bad-image-list', ( $blacklist === null ) ? 'default' 
: md5( $blacklist ) );
        $badImages = $cache->get( $key );
 
diff --git a/includes/TemplateParser.php b/includes/TemplateParser.php
index 44d264d..8ce3420 100644
--- a/includes/TemplateParser.php
+++ b/includes/TemplateParser.php
@@ -103,7 +103,7 @@
 
                if ( $secretKey ) {
                        // See if the compiled PHP code is stored in cache.
-                       $cache = ObjectCache::newAccelerator( CACHE_ANYTHING );
+                       $cache = ObjectCache::getLocalServerInstance( 
CACHE_ANYTHING );
                        $key = $cache->makeKey( 'template', $templateName, 
$fastHash );
                        $code = $this->forceRecompile ? null : $cache->get( 
$key );
 
diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php
index bcfa792..ae746e3 100644
--- a/includes/cache/MessageCache.php
+++ b/includes/cache/MessageCache.php
@@ -154,7 +154,7 @@
                $this->mExpiry = $expiry;
 
                if ( $wgUseLocalMessageCache ) {
-                       $this->localCache = ObjectCache::newAccelerator( 
CACHE_NONE );
+                       $this->localCache = 
ObjectCache::getLocalServerInstance( CACHE_NONE );
                } else {
                        $this->localCache = wfGetCache( CACHE_NONE );
                }
diff --git a/includes/db/Database.php b/includes/db/Database.php
index cf774fa..531086b 100644
--- a/includes/db/Database.php
+++ b/includes/db/Database.php
@@ -615,7 +615,7 @@
        function __construct( array $params ) {
                global $wgDBprefix, $wgDBmwschema, $wgCommandLineMode;
 
-               $this->srvCache = ObjectCache::newAccelerator( 'hash' );
+               $this->srvCache = ObjectCache::getLocalServerInstance( 'hash' );
 
                $server = $params['host'];
                $user = $params['user'];
diff --git a/includes/db/loadbalancer/LoadMonitorMySQL.php 
b/includes/db/loadbalancer/LoadMonitorMySQL.php
index f49e965..59d6ef6 100644
--- a/includes/db/loadbalancer/LoadMonitorMySQL.php
+++ b/includes/db/loadbalancer/LoadMonitorMySQL.php
@@ -36,7 +36,7 @@
        public function __construct( $parent ) {
                $this->parent = $parent;
 
-               $this->srvCache = ObjectCache::newAccelerator( 'hash' );
+               $this->srvCache = ObjectCache::getLocalServerInstance( 'hash' );
                $this->mainCache = ObjectCache::getLocalClusterInstance();
        }
 
diff --git a/includes/filebackend/SwiftFileBackend.php 
b/includes/filebackend/SwiftFileBackend.php
index 83c1da1..8097549 100644
--- a/includes/filebackend/SwiftFileBackend.php
+++ b/includes/filebackend/SwiftFileBackend.php
@@ -140,7 +140,7 @@
                                $this->srvCache = 
ObjectCache::getLocalClusterInstance();
                        } else {
                                // Look for APC, XCache, WinCache, ect...
-                               $this->srvCache = ObjectCache::newAccelerator( 
CACHE_NONE );
+                               $this->srvCache = 
ObjectCache::getLocalServerInstance( CACHE_NONE );
                        }
                } else {
                        $this->srvCache = new EmptyBagOStuff();
diff --git a/includes/filebackend/lockmanager/DBLockManager.php 
b/includes/filebackend/lockmanager/DBLockManager.php
index 9d4f009..1c389c3 100644
--- a/includes/filebackend/lockmanager/DBLockManager.php
+++ b/includes/filebackend/lockmanager/DBLockManager.php
@@ -96,7 +96,7 @@
                                // Tracks peers that couldn't be queried 
recently to avoid lengthy
                                // connection timeouts. This is useless if each 
bucket has one peer.
                                try {
-                                       $this->statusCache = 
ObjectCache::newAccelerator();
+                                       $this->statusCache = 
ObjectCache::getLocalServerInstance();
                                } catch ( Exception $e ) {
                                        trigger_error( __CLASS__ .
                                                " using multiple DB peers 
without apc, xcache, or wincache." );
diff --git a/includes/media/TransformationalImageHandler.php 
b/includes/media/TransformationalImageHandler.php
index 30f9e2e..f72df19 100644
--- a/includes/media/TransformationalImageHandler.php
+++ b/includes/media/TransformationalImageHandler.php
@@ -508,7 +508,7 @@
         * @return string|bool Representing the IM version; false on error
         */
        protected function getMagickVersion() {
-               $cache = ObjectCache::newAccelerator( CACHE_NONE );
+               $cache = ObjectCache::getLocalServerInstance( CACHE_NONE );
                return $cache->getWithSetCallback(
                        'imagemagick-version',
                        $cache::TTL_HOUR,
diff --git a/includes/objectcache/ObjectCache.php 
b/includes/objectcache/ObjectCache.php
index 3d14c33..ba58f6a 100644
--- a/includes/objectcache/ObjectCache.php
+++ b/includes/objectcache/ObjectCache.php
@@ -42,22 +42,15 @@
  *
  * Primary entry points:
  *
- * - ObjectCache::newAccelerator( $fallbackType )
- *   Purpose: Cache for very hot keys.
- *   Stored only on the individual web server.
- *   Not associated with other servers.
- *
  * - ObjectCache::getMainWANInstance()
- *   Purpose: Cache.
+ *   Purpose: Memory cache.
  *   Stored in the local data-center's main cache (uses different cache keys).
  *   Delete events are broadcasted to other DCs. See WANObjectCache for 
details.
  *
- * - ObjectCache::getMainStashInstance()
- *   Purpose: Ephemeral storage.
- *   Stored centrally within the primary data-center.
- *   Changes are applied there first and replicated to other DCs (best-effort).
- *   To retrieve the latest value (e.g. not from a slave), use 
BagOStuff:READ_LATEST.
- *   This store may be subject to LRU style evictions.
+ * - ObjectCache::getLocalServerInstance( $fallbackType )
+ *   Purpose: Memory cache for very hot keys.
+ *   Stored only on the individual web server (often EmptyBagOStuff in CLI 
mode).
+ *   Not replicated to the other servers.
  *
  * - ObjectCache::getLocalClusterInstance()
  *   Purpose: Memory storage for per-cluster coordination and tracking.
@@ -65,7 +58,15 @@
  *   Stored centrally within the local data-center. Not replicated to other 
DCs.
  *   Also known as $wgMemc. Configured by $wgMainCacheType.
  *
- * - wfGetCache( $cacheType )
+ * - ObjectCache::getMainStashInstance()
+ *   Purpose: Ephemeral global storage.
+ *   Stored centrally within the primary data-center.
+ *   Changes are applied there first and replicated to other DCs (best-effort).
+ *   To retrieve the latest value (e.g. not from a slave), use 
BagOStuff:READ_LATEST.
+ *   This store may be subject to LRU style evictions.
+ *
+ * - ObjectCache::getInstance( $cacheType )
+ *   Purpose: Special cases (like tiered memory/disk caches).
  *   Get a specific cache type by key in $wgObjectCaches.
  *
  * All the above cache instances (BagOStuff and WANObjectCache) have their 
makeKey()
@@ -236,26 +237,17 @@
         * A fallback cache can be specified if none is found.
         *
         *     // Direct calls
-        *     ObjectCache::newAccelerator( $fallbackType );
+        *     ObjectCache::getLocalServerInstance( $fallbackType );
         *
         *     // From $wgObjectCaches via newFromParams()
-        *     ObjectCache::newAccelerator( array( 'fallback' => $fallbackType 
) );
+        *     ObjectCache::getLocalServerInstance( array( 'fallback' => 
$fallbackType ) );
         *
-        * @param array $params [optional] Array key 'fallback' for $fallback.
-        * @param int|string $fallback Fallback cache, e.g. (CACHE_NONE, 
"hash") (since 1.24)
+        * @param int|string|array $fallback Fallback cache or parameter map 
with 'fallback'
         * @return BagOStuff
         * @throws MWException
+        * @since 1.27
         */
-       public static function newAccelerator( $params = array(), $fallback = 
null ) {
-               if ( $fallback === null ) {
-                       // The is_array check here is needed because in PHP 5.3:
-                       // $a = 'hash'; isset( $params['fallback'] ); yields 
true
-                       if ( is_array( $params ) && isset( $params['fallback'] 
) ) {
-                               $fallback = $params['fallback'];
-                       } elseif ( !is_array( $params ) ) {
-                               $fallback = $params;
-                       }
-               }
+       public static function getLocalServerInstance( $fallback = null ) {
                if ( function_exists( 'apc_fetch' ) ) {
                        $id = 'apc';
                } elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 
'xcache.var_size' ) ) {
@@ -267,12 +259,33 @@
                                throw new MWException( 'CACHE_ACCEL requested 
but no suitable object ' .
                                        'cache is present. You may want to 
install APC.' );
                        }
-                       $id = $fallback;
+                       $id = is_array( $fallback ) ? $fallback['fallback'] : 
$fallback;
                }
+
                return self::getInstance( $id );
        }
 
        /**
+        * @param array $params [optional] Array key 'fallback' for $fallback.
+        * @param int|string $fallback Fallback cache, e.g. (CACHE_NONE, 
"hash") (since 1.24)
+        * @return BagOStuff
+        * @deprecated 1.27
+        */
+       public static function newAccelerator( $params = array(), $fallback = 
null ) {
+               if ( $fallback === null ) {
+                       // The is_array check here is needed because in PHP 5.3:
+                       // $a = 'hash'; isset( $params['fallback'] ); yields 
true
+                       if ( is_array( $params ) && isset( $params['fallback'] 
) ) {
+                               $fallback = $params['fallback'];
+                       } elseif ( !is_array( $params ) ) {
+                               $fallback = $params;
+                       }
+               }
+
+               return self::getLocalServerInstance( $fallback );
+       }
+
+       /**
         * Create a new cache object of the specified type.
         *
         * @since 1.26
diff --git a/includes/parser/DateFormatter.php 
b/includes/parser/DateFormatter.php
index 5ffca23..edb9ff1 100644
--- a/includes/parser/DateFormatter.php
+++ b/includes/parser/DateFormatter.php
@@ -128,7 +128,7 @@
                global $wgContLang, $wgMainCacheType;
 
                $lang = $lang ? wfGetLangObj( $lang ) : $wgContLang;
-               $cache = ObjectCache::newAccelerator( $wgMainCacheType );
+               $cache = ObjectCache::getLocalServerInstance( $wgMainCacheType 
);
 
                static $dateFormatter = false;
                if ( !$dateFormatter ) {
diff --git a/includes/registration/ExtensionRegistry.php 
b/includes/registration/ExtensionRegistry.php
index 59b9249..732b4a0 100644
--- a/includes/registration/ExtensionRegistry.php
+++ b/includes/registration/ExtensionRegistry.php
@@ -86,7 +86,7 @@
                // we don't want to fail here if $wgObjectCaches is not 
configured
                // properly for APC setup
                try {
-                       $this->cache = ObjectCache::newAccelerator();
+                       $this->cache = ObjectCache::getLocalServerInstance();
                } catch ( MWException $e ) {
                        $this->cache = new EmptyBagOStuff();
                }
diff --git a/includes/resourceloader/ResourceLoader.php 
b/includes/resourceloader/ResourceLoader.php
index 5208c23..e0eee97 100644
--- a/includes/resourceloader/ResourceLoader.php
+++ b/includes/resourceloader/ResourceLoader.php
@@ -197,7 +197,7 @@
                }
 
                $stats = RequestContext::getMain()->getStats();
-               $cache = ObjectCache::newAccelerator( CACHE_ANYTHING );
+               $cache = ObjectCache::getLocalServerInstance( CACHE_ANYTHING );
 
                $key = $cache->makeGlobalKey(
                        'resourceloader',
diff --git a/includes/resourceloader/ResourceLoaderFileModule.php 
b/includes/resourceloader/ResourceLoaderFileModule.php
index ef98400..1421b10 100644
--- a/includes/resourceloader/ResourceLoaderFileModule.php
+++ b/includes/resourceloader/ResourceLoaderFileModule.php
@@ -935,7 +935,7 @@
                static $cache;
 
                if ( !$cache ) {
-                       $cache = ObjectCache::newAccelerator( CACHE_ANYTHING );
+                       $cache = ObjectCache::getLocalServerInstance( 
CACHE_ANYTHING );
                }
 
                // Construct a cache key from the LESS file name and a hash 
digest
diff --git a/includes/utils/FileContentsHasher.php 
b/includes/utils/FileContentsHasher.php
index c866919..12f6285 100644
--- a/includes/utils/FileContentsHasher.php
+++ b/includes/utils/FileContentsHasher.php
@@ -31,7 +31,7 @@
         * Constructor.
         */
        public function __construct() {
-               $this->cache = ObjectCache::newAccelerator( 'hash' );
+               $this->cache = ObjectCache::getLocalServerInstance( 'hash' );
        }
 
        /**
diff --git a/includes/utils/MWCryptHKDF.php b/includes/utils/MWCryptHKDF.php
index 740df92..2dfc902 100644
--- a/includes/utils/MWCryptHKDF.php
+++ b/includes/utils/MWCryptHKDF.php
@@ -176,7 +176,7 @@
                $context[] = gethostname();
 
                // Setup salt cache. Use APC, or fallback to the main cache if 
it isn't setup
-               $cache = ObjectCache::newAccelerator( $wgMainCacheType );
+               $cache = ObjectCache::getLocalServerInstance( $wgMainCacheType 
);
 
                if ( is_null( self::$singleton ) ) {
                        self::$singleton = new self( $secret, $wgHKDFAlgorithm, 
$cache, $context );
diff --git a/includes/utils/UIDGenerator.php b/includes/utils/UIDGenerator.php
index 04c8e19..f781435b7 100644
--- a/includes/utils/UIDGenerator.php
+++ b/includes/utils/UIDGenerator.php
@@ -283,7 +283,7 @@
                $cache = null;
                if ( ( $flags & self::QUICK_VOLATILE ) && PHP_SAPI !== 'cli' ) {
                        try {
-                               $cache = ObjectCache::newAccelerator();
+                               $cache = ObjectCache::getLocalServerInstance();
                        } catch ( Exception $e ) {
                                // not supported
                        }

-- 
To view, visit https://gerrit.wikimedia.org/r/250215
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7205a99ce033e8b086a52cd02c8a721e99c84b1e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to