Replace newAccelerator() with getLocalServerInstance()
The name is clearer and more consistent, with simpler arguments. Change-Id: I7205a99ce033e8b086a52cd02c8a721e99c84b1e
This commit is contained in:
parent
993c25c980
commit
17c91ad610
17 changed files with 59 additions and 46 deletions
|
|
@ -2211,7 +2211,7 @@ $wgObjectCaches = array(
|
||||||
CACHE_DB => array( 'class' => 'SqlBagOStuff', 'loggroup' => 'SQLBagOStuff' ),
|
CACHE_DB => array( 'class' => 'SqlBagOStuff', 'loggroup' => 'SQLBagOStuff' ),
|
||||||
|
|
||||||
CACHE_ANYTHING => array( 'factory' => 'ObjectCache::newAnything' ),
|
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' ),
|
CACHE_MEMCACHED => array( 'class' => 'MemcachedPhpBagOStuff', 'loggroup' => 'memcached' ),
|
||||||
|
|
||||||
'db-replicated' => array(
|
'db-replicated' => array(
|
||||||
|
|
|
||||||
|
|
@ -4010,7 +4010,7 @@ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) {
|
||||||
return $bad;
|
return $bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cache = ObjectCache::newAccelerator( 'hash' );
|
$cache = ObjectCache::getLocalServerInstance( 'hash' );
|
||||||
$key = wfMemcKey( 'bad-image-list', ( $blacklist === null ) ? 'default' : md5( $blacklist ) );
|
$key = wfMemcKey( 'bad-image-list', ( $blacklist === null ) ? 'default' : md5( $blacklist ) );
|
||||||
$badImages = $cache->get( $key );
|
$badImages = $cache->get( $key );
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ class TemplateParser {
|
||||||
|
|
||||||
if ( $secretKey ) {
|
if ( $secretKey ) {
|
||||||
// See if the compiled PHP code is stored in cache.
|
// 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 );
|
$key = $cache->makeKey( 'template', $templateName, $fastHash );
|
||||||
$code = $this->forceRecompile ? null : $cache->get( $key );
|
$code = $this->forceRecompile ? null : $cache->get( $key );
|
||||||
|
|
||||||
|
|
|
||||||
2
includes/cache/MessageCache.php
vendored
2
includes/cache/MessageCache.php
vendored
|
|
@ -154,7 +154,7 @@ class MessageCache {
|
||||||
$this->mExpiry = $expiry;
|
$this->mExpiry = $expiry;
|
||||||
|
|
||||||
if ( $wgUseLocalMessageCache ) {
|
if ( $wgUseLocalMessageCache ) {
|
||||||
$this->localCache = ObjectCache::newAccelerator( CACHE_NONE );
|
$this->localCache = ObjectCache::getLocalServerInstance( CACHE_NONE );
|
||||||
} else {
|
} else {
|
||||||
$this->localCache = wfGetCache( CACHE_NONE );
|
$this->localCache = wfGetCache( CACHE_NONE );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -615,7 +615,7 @@ abstract class DatabaseBase implements IDatabase {
|
||||||
function __construct( array $params ) {
|
function __construct( array $params ) {
|
||||||
global $wgDBprefix, $wgDBmwschema, $wgCommandLineMode;
|
global $wgDBprefix, $wgDBmwschema, $wgCommandLineMode;
|
||||||
|
|
||||||
$this->srvCache = ObjectCache::newAccelerator( 'hash' );
|
$this->srvCache = ObjectCache::getLocalServerInstance( 'hash' );
|
||||||
|
|
||||||
$server = $params['host'];
|
$server = $params['host'];
|
||||||
$user = $params['user'];
|
$user = $params['user'];
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class LoadMonitorMySQL implements LoadMonitor {
|
||||||
public function __construct( $parent ) {
|
public function __construct( $parent ) {
|
||||||
$this->parent = $parent;
|
$this->parent = $parent;
|
||||||
|
|
||||||
$this->srvCache = ObjectCache::newAccelerator( 'hash' );
|
$this->srvCache = ObjectCache::getLocalServerInstance( 'hash' );
|
||||||
$this->mainCache = ObjectCache::getLocalClusterInstance();
|
$this->mainCache = ObjectCache::getLocalClusterInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ class SwiftFileBackend extends FileBackendStore {
|
||||||
$this->srvCache = ObjectCache::getLocalClusterInstance();
|
$this->srvCache = ObjectCache::getLocalClusterInstance();
|
||||||
} else {
|
} else {
|
||||||
// Look for APC, XCache, WinCache, ect...
|
// Look for APC, XCache, WinCache, ect...
|
||||||
$this->srvCache = ObjectCache::newAccelerator( CACHE_NONE );
|
$this->srvCache = ObjectCache::getLocalServerInstance( CACHE_NONE );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->srvCache = new EmptyBagOStuff();
|
$this->srvCache = new EmptyBagOStuff();
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ abstract class DBLockManager extends QuorumLockManager {
|
||||||
// Tracks peers that couldn't be queried recently to avoid lengthy
|
// Tracks peers that couldn't be queried recently to avoid lengthy
|
||||||
// connection timeouts. This is useless if each bucket has one peer.
|
// connection timeouts. This is useless if each bucket has one peer.
|
||||||
try {
|
try {
|
||||||
$this->statusCache = ObjectCache::newAccelerator();
|
$this->statusCache = ObjectCache::getLocalServerInstance();
|
||||||
} catch ( Exception $e ) {
|
} catch ( Exception $e ) {
|
||||||
trigger_error( __CLASS__ .
|
trigger_error( __CLASS__ .
|
||||||
" using multiple DB peers without apc, xcache, or wincache." );
|
" using multiple DB peers without apc, xcache, or wincache." );
|
||||||
|
|
|
||||||
|
|
@ -508,7 +508,7 @@ abstract class TransformationalImageHandler extends ImageHandler {
|
||||||
* @return string|bool Representing the IM version; false on error
|
* @return string|bool Representing the IM version; false on error
|
||||||
*/
|
*/
|
||||||
protected function getMagickVersion() {
|
protected function getMagickVersion() {
|
||||||
$cache = ObjectCache::newAccelerator( CACHE_NONE );
|
$cache = ObjectCache::getLocalServerInstance( CACHE_NONE );
|
||||||
return $cache->getWithSetCallback(
|
return $cache->getWithSetCallback(
|
||||||
'imagemagick-version',
|
'imagemagick-version',
|
||||||
$cache::TTL_HOUR,
|
$cache::TTL_HOUR,
|
||||||
|
|
|
||||||
|
|
@ -42,22 +42,15 @@ use MediaWiki\Logger\LoggerFactory;
|
||||||
*
|
*
|
||||||
* Primary entry points:
|
* 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()
|
* - ObjectCache::getMainWANInstance()
|
||||||
* Purpose: Cache.
|
* Purpose: Memory cache.
|
||||||
* Stored in the local data-center's main cache (uses different cache keys).
|
* Stored in the local data-center's main cache (uses different cache keys).
|
||||||
* Delete events are broadcasted to other DCs. See WANObjectCache for details.
|
* Delete events are broadcasted to other DCs. See WANObjectCache for details.
|
||||||
*
|
*
|
||||||
* - ObjectCache::getMainStashInstance()
|
* - ObjectCache::getLocalServerInstance( $fallbackType )
|
||||||
* Purpose: Ephemeral storage.
|
* Purpose: Memory cache for very hot keys.
|
||||||
* Stored centrally within the primary data-center.
|
* Stored only on the individual web server (often EmptyBagOStuff in CLI mode).
|
||||||
* Changes are applied there first and replicated to other DCs (best-effort).
|
* Not replicated to the other servers.
|
||||||
* 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::getLocalClusterInstance()
|
* - ObjectCache::getLocalClusterInstance()
|
||||||
* Purpose: Memory storage for per-cluster coordination and tracking.
|
* Purpose: Memory storage for per-cluster coordination and tracking.
|
||||||
|
|
@ -65,7 +58,15 @@ use MediaWiki\Logger\LoggerFactory;
|
||||||
* Stored centrally within the local data-center. Not replicated to other DCs.
|
* Stored centrally within the local data-center. Not replicated to other DCs.
|
||||||
* Also known as $wgMemc. Configured by $wgMainCacheType.
|
* 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.
|
* Get a specific cache type by key in $wgObjectCaches.
|
||||||
*
|
*
|
||||||
* All the above cache instances (BagOStuff and WANObjectCache) have their makeKey()
|
* All the above cache instances (BagOStuff and WANObjectCache) have their makeKey()
|
||||||
|
|
@ -236,15 +237,39 @@ class ObjectCache {
|
||||||
* A fallback cache can be specified if none is found.
|
* A fallback cache can be specified if none is found.
|
||||||
*
|
*
|
||||||
* // Direct calls
|
* // Direct calls
|
||||||
* ObjectCache::newAccelerator( $fallbackType );
|
* ObjectCache::getLocalServerInstance( $fallbackType );
|
||||||
*
|
*
|
||||||
* // From $wgObjectCaches via newFromParams()
|
* // From $wgObjectCaches via newFromParams()
|
||||||
* ObjectCache::newAccelerator( array( 'fallback' => $fallbackType ) );
|
* ObjectCache::getLocalServerInstance( array( 'fallback' => $fallbackType ) );
|
||||||
*
|
*
|
||||||
|
* @param int|string|array $fallback Fallback cache or parameter map with 'fallback'
|
||||||
|
* @return BagOStuff
|
||||||
|
* @throws MWException
|
||||||
|
* @since 1.27
|
||||||
|
*/
|
||||||
|
public static function getLocalServerInstance( $fallback = CACHE_NONE ) {
|
||||||
|
if ( function_exists( 'apc_fetch' ) ) {
|
||||||
|
$id = 'apc';
|
||||||
|
} elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) {
|
||||||
|
$id = 'xcache';
|
||||||
|
} elseif ( function_exists( 'wincache_ucache_get' ) ) {
|
||||||
|
$id = 'wincache';
|
||||||
|
} else {
|
||||||
|
if ( is_array( $fallback ) ) {
|
||||||
|
$id = isset( $fallback['fallback'] ) ? $fallback['fallback'] : CACHE_NONE;
|
||||||
|
} else {
|
||||||
|
$id = $fallback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::getInstance( $id );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* @param array $params [optional] Array key 'fallback' for $fallback.
|
* @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 $fallback Fallback cache, e.g. (CACHE_NONE, "hash") (since 1.24)
|
||||||
* @return BagOStuff
|
* @return BagOStuff
|
||||||
* @throws MWException
|
* @deprecated 1.27
|
||||||
*/
|
*/
|
||||||
public static function newAccelerator( $params = array(), $fallback = null ) {
|
public static function newAccelerator( $params = array(), $fallback = null ) {
|
||||||
if ( $fallback === null ) {
|
if ( $fallback === null ) {
|
||||||
|
|
@ -256,20 +281,8 @@ class ObjectCache {
|
||||||
$fallback = $params;
|
$fallback = $params;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( function_exists( 'apc_fetch' ) ) {
|
|
||||||
$id = 'apc';
|
return self::getLocalServerInstance( $fallback );
|
||||||
} elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) {
|
|
||||||
$id = 'xcache';
|
|
||||||
} elseif ( function_exists( 'wincache_ucache_get' ) ) {
|
|
||||||
$id = 'wincache';
|
|
||||||
} else {
|
|
||||||
if ( $fallback === null ) {
|
|
||||||
throw new MWException( 'CACHE_ACCEL requested but no suitable object ' .
|
|
||||||
'cache is present. You may want to install APC.' );
|
|
||||||
}
|
|
||||||
$id = $fallback;
|
|
||||||
}
|
|
||||||
return self::getInstance( $id );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ class DateFormatter {
|
||||||
global $wgContLang, $wgMainCacheType;
|
global $wgContLang, $wgMainCacheType;
|
||||||
|
|
||||||
$lang = $lang ? wfGetLangObj( $lang ) : $wgContLang;
|
$lang = $lang ? wfGetLangObj( $lang ) : $wgContLang;
|
||||||
$cache = ObjectCache::newAccelerator( $wgMainCacheType );
|
$cache = ObjectCache::getLocalServerInstance( $wgMainCacheType );
|
||||||
|
|
||||||
static $dateFormatter = false;
|
static $dateFormatter = false;
|
||||||
if ( !$dateFormatter ) {
|
if ( !$dateFormatter ) {
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ class ExtensionRegistry {
|
||||||
// we don't want to fail here if $wgObjectCaches is not configured
|
// we don't want to fail here if $wgObjectCaches is not configured
|
||||||
// properly for APC setup
|
// properly for APC setup
|
||||||
try {
|
try {
|
||||||
$this->cache = ObjectCache::newAccelerator();
|
$this->cache = ObjectCache::getLocalServerInstance();
|
||||||
} catch ( MWException $e ) {
|
} catch ( MWException $e ) {
|
||||||
$this->cache = new EmptyBagOStuff();
|
$this->cache = new EmptyBagOStuff();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ class ResourceLoader implements LoggerAwareInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
$stats = RequestContext::getMain()->getStats();
|
$stats = RequestContext::getMain()->getStats();
|
||||||
$cache = ObjectCache::newAccelerator( CACHE_ANYTHING );
|
$cache = ObjectCache::getLocalServerInstance( CACHE_ANYTHING );
|
||||||
|
|
||||||
$key = $cache->makeGlobalKey(
|
$key = $cache->makeGlobalKey(
|
||||||
'resourceloader',
|
'resourceloader',
|
||||||
|
|
|
||||||
|
|
@ -935,7 +935,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
|
||||||
static $cache;
|
static $cache;
|
||||||
|
|
||||||
if ( !$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
|
// Construct a cache key from the LESS file name and a hash digest
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class FileContentsHasher {
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->cache = ObjectCache::newAccelerator( 'hash' );
|
$this->cache = ObjectCache::getLocalServerInstance( 'hash' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@ class MWCryptHKDF {
|
||||||
$context[] = gethostname();
|
$context[] = gethostname();
|
||||||
|
|
||||||
// Setup salt cache. Use APC, or fallback to the main cache if it isn't setup
|
// 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 ) ) {
|
if ( is_null( self::$singleton ) ) {
|
||||||
self::$singleton = new self( $secret, $wgHKDFAlgorithm, $cache, $context );
|
self::$singleton = new self( $secret, $wgHKDFAlgorithm, $cache, $context );
|
||||||
|
|
|
||||||
|
|
@ -283,7 +283,7 @@ class UIDGenerator {
|
||||||
$cache = null;
|
$cache = null;
|
||||||
if ( ( $flags & self::QUICK_VOLATILE ) && PHP_SAPI !== 'cli' ) {
|
if ( ( $flags & self::QUICK_VOLATILE ) && PHP_SAPI !== 'cli' ) {
|
||||||
try {
|
try {
|
||||||
$cache = ObjectCache::newAccelerator();
|
$cache = ObjectCache::getLocalServerInstance();
|
||||||
} catch ( Exception $e ) {
|
} catch ( Exception $e ) {
|
||||||
// not supported
|
// not supported
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue