Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/246457
Change subject: Convert some users to WANObjectCache for consistency
......................................................................
Convert some users to WANObjectCache for consistency
These callers don't need to do purges, but can still perfectly
take advantage of this instance over a plain BagOStuff.
Change-Id: I8e362df451c0c28731fc853c044c4c4b8e097f01
---
M includes/AjaxResponse.php
M includes/Block.php
M includes/Revision.php
M includes/SiteStats.php
M includes/api/ApiHelp.php
M includes/api/ApiMain.php
M includes/cache/BacklinkCache.php
M includes/diff/DifferenceEngine.php
8 files changed, 51 insertions(+), 58 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/57/246457/1
diff --git a/includes/AjaxResponse.php b/includes/AjaxResponse.php
index 6c2efc2..34bb65f 100644
--- a/includes/AjaxResponse.php
+++ b/includes/AjaxResponse.php
@@ -276,13 +276,11 @@
* @return bool
*/
function loadFromMemcached( $mckey, $touched ) {
- global $wgMemc;
-
if ( !$touched ) {
return false;
}
- $mcvalue = $wgMemc->get( $mckey );
+ $mcvalue = ObjectCache::getMainWANInstance()->get( $mckey );
if ( $mcvalue ) {
# Check to see if the value has been invalidated
if ( $touched <= $mcvalue['timestamp'] ) {
@@ -304,9 +302,7 @@
* @return bool
*/
function storeInMemcached( $mckey, $expiry = 86400 ) {
- global $wgMemc;
-
- $wgMemc->set( $mckey,
+ ObjectCache::getMainWANInstance()->set( $mckey,
array(
'timestamp' => wfTimestampNow(),
'value' => $this->mText
diff --git a/includes/Block.php b/includes/Block.php
index 0ec4ad1..5dee23e 100644
--- a/includes/Block.php
+++ b/includes/Block.php
@@ -679,16 +679,17 @@
* @return bool
*/
public static function isWhitelistedFromAutoblocks( $ip ) {
- global $wgMemc;
-
// Try to get the autoblock_whitelist from the cache, as it's
faster
// than getting the msg raw and explode()'ing it.
- $key = wfMemcKey( 'ipb', 'autoblock', 'whitelist' );
- $lines = $wgMemc->get( $key );
- if ( !$lines ) {
- $lines = explode( "\n", wfMessage(
'autoblock_whitelist' )->inContentLanguage()->plain() );
- $wgMemc->set( $key, $lines, 3600 * 24 );
- }
+
+ $lines = ObjectCache::getMainWANInstance()->getWithSetCallback(
+ wfMemcKey( 'ipb', 'autoblock', 'whitelist' ),
+ 86400,
+ function () {
+ return explode( "\n",
+ wfMessage( 'autoblock_whitelist'
)->inContentLanguage()->plain() );
+ }
+ );
wfDebug( "Checking the autoblock whitelist..\n" );
diff --git a/includes/Revision.php b/includes/Revision.php
index 24c025f..a498817 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -1530,12 +1530,13 @@
*/
protected function loadText() {
// Caching may be beneficial for massive use of external storage
- global $wgRevisionCacheExpiry, $wgMemc;
+ global $wgRevisionCacheExpiry;
+ $cache = ObjectCache::getMainWANInstance();
$textId = $this->getTextId();
$key = wfMemcKey( 'revisiontext', 'textid', $textId );
if ( $wgRevisionCacheExpiry ) {
- $text = $wgMemc->get( $key );
+ $text = $cache->get( $key );
if ( is_string( $text ) ) {
wfDebug( __METHOD__ . ": got id $textId from
cache\n" );
return $text;
@@ -1582,7 +1583,7 @@
# No negative caching -- negative hits on text rows may be due
to corrupted slave servers
if ( $wgRevisionCacheExpiry && $text !== false ) {
- $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
+ $cache->set( $key, $text, $wgRevisionCacheExpiry );
}
return $text;
diff --git a/includes/SiteStats.php b/includes/SiteStats.php
index 76e7f7e..b84d2bf 100644
--- a/includes/SiteStats.php
+++ b/includes/SiteStats.php
@@ -180,23 +180,23 @@
* @return int
*/
static function numberingroup( $group ) {
- if ( !isset( self::$groupMemberCounts[$group] ) ) {
- global $wgMemc;
- $key = wfMemcKey( 'SiteStats', 'groupcounts', $group );
- $hit = $wgMemc->get( $key );
- if ( !$hit ) {
+ return ObjectCache::getMainWANInstance()->getWithSetCallback(
+ wfMemcKey( 'SiteStats', 'groupcounts', $group ),
+ 3600,
+ function ( $oldValue, &$ttl, array &$setOpts ) use (
$group ) {
$dbr = wfGetDB( DB_SLAVE );
- $hit = $dbr->selectField(
+
+ $setOpts += $dbr->getCacheSetOptions();
+
+ return $dbr->selectField(
'user_groups',
'COUNT(*)',
array( 'ug_group' => $group ),
__METHOD__
);
- $wgMemc->set( $key, $hit, 3600 );
- }
- self::$groupMemberCounts[$group] = $hit;
- }
- return self::$groupMemberCounts[$group];
+ },
+ array( 'pcTTL' => 10 )
+ );
}
/**
diff --git a/includes/api/ApiHelp.php b/includes/api/ApiHelp.php
index abec828..c33b27b 100644
--- a/includes/api/ApiHelp.php
+++ b/includes/api/ApiHelp.php
@@ -91,7 +91,7 @@
* @return string
*/
public static function getHelp( IContextSource $context, $modules,
array $options ) {
- global $wgMemc, $wgContLang;
+ global $wgContLang;
if ( !is_array( $modules ) ) {
$modules = array( $modules );
@@ -104,6 +104,7 @@
}
$out->setPageTitle( $context->msg( 'api-help-title' ) );
+ $cache = ObjectCache::getMainWANInstance();
$cacheKey = null;
if ( count( $modules ) == 1 && $modules[0] instanceof ApiMain &&
$options['recursivesubmodules'] &&
$context->getLanguage() === $wgContLang
@@ -114,7 +115,7 @@
$cacheKey = wfMemcKey( 'apihelp',
$modules[0]->getModulePath(),
(int)!empty( $options['toc'] ),
str_replace( ' ', '_',
SpecialVersion::getVersion( 'nodb' ) ) );
- $cached = $wgMemc->get( $cacheKey );
+ $cached = $cache->get( $cacheKey );
if ( $cached ) {
$out->addHTML( $cached );
return;
@@ -151,7 +152,7 @@
$out->addHTML( $html );
if ( $cacheKey !== null ) {
- $wgMemc->set( $cacheKey, $out->getHTML(),
$cacheHelpTimeout );
+ $cache->set( $cacheKey, $out->getHTML(),
$cacheHelpTimeout );
}
}
diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php
index 5d2db47..bb6782d 100644
--- a/includes/api/ApiMain.php
+++ b/includes/api/ApiMain.php
@@ -1596,25 +1596,19 @@
*/
public function makeHelpMsg() {
wfDeprecated( __METHOD__, '1.25' );
- global $wgMemc;
+
$this->setHelp();
- // Get help text from cache if present
- $key = wfMemcKey( 'apihelp', $this->getModuleName(),
- str_replace( ' ', '_', SpecialVersion::getVersion(
'nodb' ) ) );
-
$cacheHelpTimeout = $this->getConfig()->get(
'APICacheHelpTimeout' );
- if ( $cacheHelpTimeout > 0 ) {
- $cached = $wgMemc->get( $key );
- if ( $cached ) {
- return $cached;
- }
- }
- $retval = $this->reallyMakeHelpMsg();
- if ( $cacheHelpTimeout > 0 ) {
- $wgMemc->set( $key, $retval, $cacheHelpTimeout );
- }
- return $retval;
+ $that = $this;
+ return ObjectCache::getMainWANInstance()->getWithSetCallback(
+ wfMemcKey( 'apihelp', $this->getModuleName(),
+ str_replace( ' ', '_',
SpecialVersion::getVersion( 'nodb' ) ) ),
+ $cacheHelpTimeout > 0 ? $cacheHelpTimeout :
WANObjectCache::TTL_UNCACHEABLE,
+ function () use ( $that ) {
+ return $that->reallyMakeHelpMsg();
+ }
+ );
}
/**
diff --git a/includes/cache/BacklinkCache.php b/includes/cache/BacklinkCache.php
index 549ac84..3ba4f61 100644
--- a/includes/cache/BacklinkCache.php
+++ b/includes/cache/BacklinkCache.php
@@ -323,8 +323,9 @@
* @return int
*/
public function getNumLinks( $table, $max = INF ) {
- global $wgMemc, $wgUpdateRowsPerJob;
+ global $wgUpdateRowsPerJob;
+ $cache = ObjectCache::getMainWANInstance();
// 1) try partition cache ...
if ( isset( $this->partitionCache[$table] ) ) {
$entry = reset( $this->partitionCache[$table] );
@@ -340,7 +341,7 @@
$memcKey = wfMemcKey( 'numbacklinks', md5(
$this->title->getPrefixedDBkey() ), $table );
// 3) ... fallback to memcached ...
- $count = $wgMemc->get( $memcKey );
+ $count = $cache->get( $memcKey );
if ( $count ) {
return min( $max, $count );
}
@@ -355,7 +356,7 @@
// Fetch the full title info, since the caller will
likely need it next
$count = $this->getLinks( $table, false, false, $max
)->count();
if ( $count < $max ) { // full count
- $wgMemc->set( $memcKey, $count,
self::CACHE_EXPIRY );
+ $cache->set( $memcKey, $count,
self::CACHE_EXPIRY );
}
}
@@ -372,8 +373,6 @@
* @return array
*/
public function partition( $table, $batchSize ) {
- global $wgMemc;
-
// 1) try partition cache ...
if ( isset( $this->partitionCache[$table][$batchSize] ) ) {
wfDebug( __METHOD__ . ": got from partition cache\n" );
@@ -381,6 +380,7 @@
return
$this->partitionCache[$table][$batchSize]['batches'];
}
+ $cache = ObjectCache::getMainWANInstance();
$this->partitionCache[$table][$batchSize] = false;
$cacheEntry =& $this->partitionCache[$table][$batchSize];
@@ -400,7 +400,7 @@
);
// 3) ... fallback to memcached ...
- $memcValue = $wgMemc->get( $memcKey );
+ $memcValue = $cache->get( $memcKey );
if ( is_array( $memcValue ) ) {
$cacheEntry = $memcValue;
wfDebug( __METHOD__ . ": got from memcached $memcKey\n"
);
@@ -432,11 +432,11 @@
}
// Save partitions to memcached
- $wgMemc->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY );
+ $cache->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY );
// Save backlink count to memcached
$memcKey = wfMemcKey( 'numbacklinks', md5(
$this->title->getPrefixedDBkey() ), $table );
- $wgMemc->set( $memcKey, $cacheEntry['numRows'],
self::CACHE_EXPIRY );
+ $cache->set( $memcKey, $cacheEntry['numRows'],
self::CACHE_EXPIRY );
wfDebug( __METHOD__ . ": got from database\n" );
diff --git a/includes/diff/DifferenceEngine.php
b/includes/diff/DifferenceEngine.php
index 6544078..ae610fa 100644
--- a/includes/diff/DifferenceEngine.php
+++ b/includes/diff/DifferenceEngine.php
@@ -680,7 +680,6 @@
* @return mixed (string/false)
*/
public function getDiffBody() {
- global $wgMemc;
$this->mCacheHit = true;
// Check if the diff should be hidden from this user
if ( !$this->loadRevisionData() ) {
@@ -702,12 +701,13 @@
}
// Cacheable?
$key = false;
+ $cache = ObjectCache::getMainWANInstance();
if ( $this->mOldid && $this->mNewid ) {
$key = $this->getDiffBodyCacheKey();
// Try cache
if ( !$this->mRefreshCache ) {
- $difftext = $wgMemc->get( $key );
+ $difftext = $cache->get( $key );
if ( $difftext ) {
wfIncrStats( 'diff_cache.hit' );
$difftext = $this->localiseLineNumbers(
$difftext );
@@ -731,7 +731,7 @@
wfIncrStats( 'diff_cache.uncacheable' );
} elseif ( $key !== false && $difftext !== false ) {
wfIncrStats( 'diff_cache.miss' );
- $wgMemc->set( $key, $difftext, 7 * 86400 );
+ $cache->set( $key, $difftext, 7 * 86400 );
} else {
wfIncrStats( 'diff_cache.uncacheable' );
}
--
To view, visit https://gerrit.wikimedia.org/r/246457
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8e362df451c0c28731fc853c044c4c4b8e097f01
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