From 79ce51d1c90c350903916e995f8ed71083ad20bd Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 24 Aug 2015 22:46:54 +0200 Subject: [PATCH] objectcache: Make first parameter of newAccelerator optional Makes it more convenient to use. Change-Id: I1e11f7a759bd2816e47d1c2453cbe39b8f44b2f0 --- includes/TemplateParser.php | 2 +- includes/cache/MessageCache.php | 2 +- includes/db/LoadMonitorMySQL.php | 2 +- includes/filebackend/SwiftFileBackend.php | 2 +- includes/filebackend/lockmanager/DBLockManager.php | 2 +- includes/objectcache/ObjectCache.php | 7 +++++-- includes/registration/ExtensionRegistry.php | 2 +- includes/utils/MWCryptHKDF.php | 2 +- includes/utils/UIDGenerator.php | 2 +- 9 files changed, 13 insertions(+), 10 deletions(-) diff --git a/includes/TemplateParser.php b/includes/TemplateParser.php index f0a1ebb0c1..d6b101b26d 100644 --- a/includes/TemplateParser.php +++ b/includes/TemplateParser.php @@ -103,7 +103,7 @@ class TemplateParser { // See if the compiled PHP code is stored in cache. // CACHE_ACCEL throws an exception if no suitable object cache is present, so fall // back to CACHE_ANYTHING. - $cache = ObjectCache::newAccelerator( array(), CACHE_ANYTHING ); + $cache = ObjectCache::newAccelerator( CACHE_ANYTHING ); $key = wfMemcKey( 'template', $templateName, $fastHash ); $code = $this->forceRecompile ? null : $cache->get( $key ); diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php index dafb59d0f2..f11a6482a8 100644 --- a/includes/cache/MessageCache.php +++ b/includes/cache/MessageCache.php @@ -160,7 +160,7 @@ class MessageCache { $this->mExpiry = $expiry; if ( $wgUseLocalMessageCache ) { - $this->localCache = ObjectCache::newAccelerator( array(), CACHE_NONE ); + $this->localCache = ObjectCache::newAccelerator( CACHE_NONE ); } else { $this->localCache = wfGetCache( CACHE_NONE ); } diff --git a/includes/db/LoadMonitorMySQL.php b/includes/db/LoadMonitorMySQL.php index c80697be54..752d009171 100644 --- a/includes/db/LoadMonitorMySQL.php +++ b/includes/db/LoadMonitorMySQL.php @@ -38,7 +38,7 @@ class LoadMonitorMySQL implements LoadMonitor { $this->parent = $parent; - $this->srvCache = ObjectCache::newAccelerator( array(), 'hash' ); + $this->srvCache = ObjectCache::newAccelerator( 'hash' ); $this->mainCache = $wgMemc ?: wfGetMainCache(); } diff --git a/includes/filebackend/SwiftFileBackend.php b/includes/filebackend/SwiftFileBackend.php index 6a0f2ee3e6..b49c4c59be 100644 --- a/includes/filebackend/SwiftFileBackend.php +++ b/includes/filebackend/SwiftFileBackend.php @@ -139,7 +139,7 @@ class SwiftFileBackend extends FileBackendStore { $this->srvCache = wfGetMainCache(); // preferrably memcached } else { try { // look for APC, XCache, WinCache, ect... - $this->srvCache = ObjectCache::newAccelerator( array() ); + $this->srvCache = ObjectCache::newAccelerator(); } catch ( Exception $e ) { } } diff --git a/includes/filebackend/lockmanager/DBLockManager.php b/includes/filebackend/lockmanager/DBLockManager.php index 39a55635c0..b81cf3e497 100644 --- a/includes/filebackend/lockmanager/DBLockManager.php +++ b/includes/filebackend/lockmanager/DBLockManager.php @@ -96,7 +96,7 @@ abstract class DBLockManager extends QuorumLockManager { // 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( array() ); + $this->statusCache = ObjectCache::newAccelerator(); } catch ( Exception $e ) { trigger_error( __CLASS__ . " using multiple DB peers without apc, xcache, or wincache." ); diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index 8a99f53f41..5872831563 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -158,12 +158,15 @@ class ObjectCache { * This will look for any APC style server-local cache. * A fallback cache can be specified if none is found. * - * @param array $params + * @param array $params [optional] * @param int|string $fallback Fallback cache, e.g. (CACHE_NONE, "hash") (since 1.24) * @return BagOStuff * @throws MWException */ - static function newAccelerator( $params, $fallback = null ) { + static function newAccelerator( $params = array(), $fallback = null ) { + if ( !is_array( $params ) && $fallback === null ) { + $fallback = $params; + } if ( function_exists( 'apc_fetch' ) ) { $id = 'apc'; } elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) { diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php index 7414925f48..b89518ad28 100644 --- a/includes/registration/ExtensionRegistry.php +++ b/includes/registration/ExtensionRegistry.php @@ -81,7 +81,7 @@ class ExtensionRegistry { // we don't want to fail here if $wgObjectCaches is not configured // properly for APC setup try { - $this->cache = ObjectCache::newAccelerator( array() ); + $this->cache = ObjectCache::newAccelerator(); } catch ( MWException $e ) { $this->cache = new EmptyBagOStuff(); } diff --git a/includes/utils/MWCryptHKDF.php b/includes/utils/MWCryptHKDF.php index 950dd846f1..1ddd119511 100644 --- a/includes/utils/MWCryptHKDF.php +++ b/includes/utils/MWCryptHKDF.php @@ -177,7 +177,7 @@ class MWCryptHKDF { // Setup salt cache. Use APC, or fallback to the main cache if it isn't setup try { - $cache = ObjectCache::newAccelerator( array() ); + $cache = ObjectCache::newAccelerator(); } catch ( Exception $e ) { $cache = wfGetMainCache(); } diff --git a/includes/utils/UIDGenerator.php b/includes/utils/UIDGenerator.php index 2d7d932331..04c8e1945c 100644 --- a/includes/utils/UIDGenerator.php +++ b/includes/utils/UIDGenerator.php @@ -283,7 +283,7 @@ class UIDGenerator { $cache = null; if ( ( $flags & self::QUICK_VOLATILE ) && PHP_SAPI !== 'cli' ) { try { - $cache = ObjectCache::newAccelerator( array() ); + $cache = ObjectCache::newAccelerator(); } catch ( Exception $e ) { // not supported } -- 2.20.1