X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fobjectcache%2FObjectCache.php;h=90a9f7c84235465b708f31d25c793f4a32ad86d4;hb=e2a7988178698b4369c7963d20610ee622db3ee7;hp=cb783a7efd6929d916b20d645e289f1c943de5cb;hpb=f5772f54126d489e31781d34db3db989992fa108;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index cb783a7efd..90a9f7c842 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -42,30 +42,32 @@ use MediaWiki\Logger\LoggerFactory; * * 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. - * Stored in the local data-center's main cache (uses different cache keys). - * Delete events are broadcasted to other DCs. See WANObjectCache for details. + * Purpose: Memory cache. + * Stored in the local data-center's main cache (keyspace different from local-cluster cache). + * Delete events are broadcasted to other DCs main cache. 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 (typically APC for web requests, + * and EmptyBagOStuff in CLI mode). + * Not replicated to the other servers. * * - ObjectCache::getLocalClusterInstance() * Purpose: Memory storage for per-cluster coordination and tracking. * A typical use case would be a rate limit counter or cache regeneration mutex. * Stored centrally within the local data-center. Not replicated to other DCs. - * Also known as $wgMemc. Configured by $wgMainCacheType. + * Configured by $wgMainCacheType. + * + * - 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. * - * - wfGetCache( $cacheType ) + * - 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() @@ -137,19 +139,14 @@ class ObjectCache { * @return string */ public static function getDefaultKeyspace() { - global $wgCachePrefix, $wgDBname, $wgDBprefix; + global $wgCachePrefix; $keyspace = $wgCachePrefix; if ( is_string( $keyspace ) && $keyspace !== '' ) { return $keyspace; } - $keyspace = $wgDBname; - if ( is_string( $wgDBprefix ) && $wgDBprefix !== '' ) { - $keyspace .= '-' . $wgDBprefix; - } - - return $keyspace; + return wfWikiID(); } /** @@ -167,8 +164,6 @@ class ObjectCache { if ( isset( $params['loggroup'] ) ) { $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] ); } else { - // For backwards-compatability with custom parameters, lets not - // have all logging suddenly disappear $params['logger'] = LoggerFactory::getInstance( 'objectcache' ); } if ( !isset( $params['keyspace'] ) ) { @@ -238,15 +233,39 @@ class ObjectCache { * 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 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 int|string $fallback Fallback cache, e.g. (CACHE_NONE, "hash") (since 1.24) * @return BagOStuff - * @throws MWException + * @deprecated 1.27 */ public static function newAccelerator( $params = array(), $fallback = null ) { if ( $fallback === null ) { @@ -258,20 +277,8 @@ class ObjectCache { $fallback = $params; } } - 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 ( $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::newFromId( $id ); + + return self::getLocalServerInstance( $fallback ); } /** @@ -294,6 +301,11 @@ class ObjectCache { $class = $params['relayerConfig']['class']; $params['relayer'] = new $class( $params['relayerConfig'] ); $params['cache'] = self::newFromId( $params['cacheId'] ); + if ( isset( $params['loggroup'] ) ) { + $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] ); + } else { + $params['logger'] = LoggerFactory::getInstance( 'objectcache' ); + } $class = $params['class']; return new $class( $params );