Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/258163
Change subject: [WIP] Add $wgObjectCacheGroups and ObjectCache::getGroup()
......................................................................
[WIP] Add $wgObjectCacheGroups and ObjectCache::getGroup()
Still a work in progress. Need to figure out how to properly
provide back-compat and whether to export live values from
$wgObjectCacheGroups in two directions or just one.
Bug: T115890
Change-Id: I2817204ce2e3837692be7bf62090e217cb96952f
---
M includes/DefaultSettings.php
M includes/GlobalFunctions.php
M includes/Setup.php
M includes/objectcache/ObjectCache.php
4 files changed, 100 insertions(+), 46 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/63/258163/1
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index de364a6..fcd618d 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -2146,65 +2146,72 @@
* limited space. By default, it is disabled, since the stock database cache
* is not fast enough to make it worthwhile.
*
- * The options are:
- *
- * - CACHE_ANYTHING: Use anything, as long as it works
- * - CACHE_NONE: Do not cache
- * - CACHE_DB: Store cache objects in the DB
- * - CACHE_MEMCACHED: MemCached, must specify servers in $wgMemCachedServers
- * - CACHE_ACCEL: APC, XCache or WinCache
- * - (other): A string may be used which identifies a cache
- * configuration in $wgObjectCaches.
- *
- * @see $wgMessageCacheType, $wgParserCacheType
+ * @see $wgObjectCacheGroups
+ * @var string A key in $wgObjectCaches
*/
$wgMainCacheType = CACHE_NONE;
/**
- * The cache type for storing the contents of the MediaWiki namespace. This
- * cache is used for a small amount of data which is expensive to regenerate.
+ * The cache type for caching the contents of the MediaWiki namespace.
*
- * For available types see $wgMainCacheType.
+ * This typically contains a small number of keys only.
+ * Values are expensive to regenerate however.
+ *
+ * @deprecated since 1.27 Use $wgObjectCacheGroups['message-cache']
+ * @see MessageCache class
+ * @var string A key in $wgObjectCaches
*/
-$wgMessageCacheType = CACHE_ANYTHING;
+$wgMessageCacheType = false;
/**
- * The cache type for storing article HTML. This is used to store data which
- * is expensive to regenerate, and benefits from having plenty of storage
space.
+ * The cache type for storing parser output HTML.
*
- * For available types see $wgMainCacheType.
+ * These values are expensive to regenerate. Benefits from high storage
capacity.
+ * Can be disabled by $wgEnableParserCache.
+ *
+ * @deprecated since 1.27 Use $wgObjectCacheGroups['parser']
+ * @var string A key in $wgObjectCaches
*/
-$wgParserCacheType = CACHE_ANYTHING;
+$wgParserCacheType = false;
/**
- * The cache type for storing session data. Used if $wgSessionsInObjectCache
is true.
+ * The cache type for storing session data.
*
- * For available types see $wgMainCacheType.
+ * Used if $wgSessionsInObjectCache is true.
+ *
+ * @deprecated since 1.27 Use $wgObjectCacheGroups['session']
+ * @var string A key in $wgObjectCaches
*/
-$wgSessionCacheType = CACHE_ANYTHING;
+$wgSessionCacheType = false;
/**
* The cache type for storing language conversion tables,
* which are used when parsing certain text and interface messages.
*
- * For available types see $wgMainCacheType.
- *
+ * @deprecated since 1.27 Use $wgObjectCacheGroups['language-converter']
+ * @var string A key in $wgObjectCaches
* @since 1.20
*/
-$wgLanguageConverterCacheType = CACHE_ANYTHING;
+$wgLanguageConverterCacheType = false;
/**
* Advanced object cache configuration.
*
* Use this to define the class names and constructor parameters which are used
- * for the various cache types. Custom cache types may be defined here and
- * referenced from $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType,
- * or $wgLanguageConverterCacheType.
+ * for the various cache types (see $wgMainCacheType and $wgObjectCacheGroups).
*
* The format is an associative array where the key is a cache identifier, and
* the value is an associative array of parameters. The "class" parameter is
the
* class name which will be used. Alternatively, a "factory" parameter may be
* given, giving a callable function which will generate a suitable cache
object.
+ *
+ * Special options:
+ *
+ * - CACHE_ANYTHING: Shortcut for using $wgMainCacheType with fallback to
CACHE_DB.
+ * - CACHE_NONE: Do not cache
+ * - CACHE_DB: Store cache objects in the database
+ * - CACHE_MEMCACHED: Memcached, must specify servers in $wgMemCachedServers
+ * - CACHE_ACCEL: Put it one of auto-detected APC, XCache or WinCache
*/
$wgObjectCaches = array(
CACHE_NONE => array( 'class' => 'EmptyBagOStuff' ),
@@ -2233,6 +2240,25 @@
'memcached-php' => array( 'class' => 'MemcachedPhpBagOStuff',
'loggroup' => 'memcached' ),
'memcached-pecl' => array( 'class' => 'MemcachedPeclBagOStuff',
'loggroup' => 'memcached' ),
'hash' => array( 'class' => 'HashBagOStuff' ),
+);
+
+/**
+ * Map of string cache group names to object cache identifiers.
+ *
+ * Any group not specified defaults to $wgMainCacheType.
+ *
+ * @code
+ * $wgObjectCacheGroups['messsage-cache'] = CACHE_ACCEL;
+ * @endcode
+ *
+ * @see $wgObjectCaches
+ * @since 1.27
+ */
+$wgObjectCacheGroups = array(
+ 'message-cache' => CACHE_ANYTHING,
+ 'parser' => CACHE_ANYTHING,
+ 'session' => CACHE_ANYTHING,
+ 'language-converter' => CACHE_ANYTHING,
);
/**
@@ -2360,7 +2386,8 @@
/**
* Set this to true to maintain a copy of the message cache on the local
server.
*
- * This layer of message cache is in addition to the one configured by
$wgMessageCacheType.
+ * This layer of message cache is in addition to the one configured
+ * by $wgObjectCacheGroups['message-cache'].
*
* The local copy is put in APC. If APC is not installed, this setting does
nothing.
*
diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index 4c85bd6..168cad4 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -3906,6 +3906,7 @@
/**
* Get a specific cache object.
*
+ * @deprecated since 1.27 Use ObjectCache::getInstance
* @param int|string $cacheType A CACHE_* constants, or other key in
$wgObjectCaches
* @return BagOStuff
*/
@@ -3916,31 +3917,31 @@
/**
* Get the main cache object
*
+ * @deprecated since 1.27 Use ObjectCache::getLocalClusterInstance()
* @return BagOStuff
*/
function wfGetMainCache() {
- global $wgMainCacheType;
- return ObjectCache::getInstance( $wgMainCacheType );
+ return ObjectCache::getLocalClusterInstance();
}
/**
- * Get the cache object used by the message cache
+ * Get the cache object for MessageCache
*
+ * @deprecated since 1.27 Use ObjectCache::getGroup( 'message-cache' )
* @return BagOStuff
*/
function wfGetMessageCacheStorage() {
- global $wgMessageCacheType;
- return ObjectCache::getInstance( $wgMessageCacheType );
+ return ObjectCache::getGroup( 'message-cache' );
}
/**
- * Get the cache object used by the parser cache
+ * Get the cache object for the parser cache
*
+ * @deprecated since 1.27 Use ObjectCache::getGroup( 'parser' )
* @return BagOStuff
*/
function wfGetParserCacheStorage() {
- global $wgParserCacheType;
- return ObjectCache::getInstance( $wgParserCacheType );
+ return ObjectCache::getGroup( 'parser' );
}
/**
diff --git a/includes/Setup.php b/includes/Setup.php
index a94bd12..b911272 100644
--- a/includes/Setup.php
+++ b/includes/Setup.php
@@ -110,6 +110,27 @@
$wgParserCacheType = CACHE_NONE;
}
+// Backwards compatibility with deprecated alias
+// Must be before call to wfSetupSession()
+if ( $wgSessionsInMemcached ) {
+ $wgSessionsInObjectCache = true;
+}
+
+// Backwards compatibility for deprecated cache configuration
+if ( $wgMessageCacheType !== false ) {
+ $wgObjectCacheGroups['message-cache'] = $wgMessageCacheType;
+}
+if ( $wgParserCacheType !== false ) {
+ $wgObjectCacheGroups['parser'] = $wgParserCacheType;
+}
+if ( $wgSessionCacheType !== false ) {
+ $wgObjectCacheGroups['session'] = $wgSessionCacheType;
+}
+if ( $wgLanguageConverterCacheType !== false ) {
+ $wgObjectCacheGroups['language-converter'] =
$wgLanguageConverterCacheType;
+}
+
+
// Fix path to icon images after they were moved in 1.24
if ( $wgRightsIcon ) {
$wgRightsIcon = str_replace(
@@ -484,12 +505,6 @@
if ( $wgMaximalPasswordLength !== false ) {
$wgPasswordPolicy['policies']['default']['MaximalPasswordLength'] =
$wgMaximalPasswordLength;
-}
-
-// Backwards compatibility with deprecated alias
-// Must be before call to wfSetupSession()
-if ( $wgSessionsInMemcached ) {
- $wgSessionsInObjectCache = true;
}
Profiler::instance()->scopedProfileOut( $ps_default );
diff --git a/includes/objectcache/ObjectCache.php
b/includes/objectcache/ObjectCache.php
index 90a9f7c..a4a44a7 100644
--- a/includes/objectcache/ObjectCache.php
+++ b/includes/objectcache/ObjectCache.php
@@ -97,6 +97,20 @@
}
/**
+ * Get a cached instance of the specified cache type for a given group.
+ *
+ * @param string $name A key in $wgObjectCacheGroups.
+ * @return BagOStuff
+ */
+ public static function getGroup( $name ) {
+ global $wgObjectCacheGroups;
+ if ( !isset( $wgObjectCacheGroups[$name] ) ) {
+ return self::getLocalClusterInstance();
+ }
+ return self::getInstance( $wgObjectCacheGroups[$name] );
+ }
+
+ /**
* Get a cached instance of the specified type of WAN cache object.
*
* @since 1.26
@@ -319,7 +333,6 @@
*/
public static function getLocalClusterInstance() {
global $wgMainCacheType;
-
return self::getInstance( $wgMainCacheType );
}
@@ -331,7 +344,6 @@
*/
public static function getMainWANInstance() {
global $wgMainWANCache;
-
return self::getWANInstance( $wgMainWANCache );
}
@@ -355,7 +367,6 @@
*/
public static function getMainStashInstance() {
global $wgMainStash;
-
return self::getInstance( $wgMainStash );
}
--
To view, visit https://gerrit.wikimedia.org/r/258163
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2817204ce2e3837692be7bf62090e217cb96952f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits