* @param bool $useDB
* @param int $expiry Lifetime for cache. @see $mExpiry.
*/
- function __construct( $memCached, $useDB, $expiry ) {
+ function __construct( BagOStuff $memCached, $useDB, $expiry ) {
global $wgUseLocalMessageCache;
- if ( !$memCached ) {
- $memCached = wfGetCache( CACHE_NONE );
- }
-
$this->mMemc = $memCached;
$this->mDisable = !$useDB;
$this->mExpiry = $expiry;
if ( $text === false ) {
// Failed to fetch data; possible ES errors?
// Store a marker to fetch on-demand as a workaround...
+ // TODO Use a differnt marker
$entry = '!TOO BIG';
wfDebugLog(
'MessageCache',
$cache['VERSION'] = MSG_CACHE_VERSION;
ksort( $cache );
+
+ # Hash for validating local cache (APC). No need to take into account
+ # messages larger than $wgMaxMsgCacheEntrySize, since those are only
+ # stored and fetched from memcache.
$cache['HASH'] = md5( serialize( $cache ) );
$cache['EXPIRY'] = wfTimestamp( TS_MW, time() + $this->mExpiry );
}
ScopedCallback::consume( $scopedLock );
- // Relay the purge to APC and other DCs
+ // Relay the purge. Touching this check key expires cache contents
+ // and local cache (APC) validation hash across all datacenters.
$this->wanCache->touchCheckKey( wfMemcKey( 'messages', $code ) );
// Also delete cached sidebar... just in case it is affected
return false;
}
- # Try the individual message cache
+ // Try the individual message cache
$titleKey = wfMemcKey( 'messages', 'individual', $title );
- $entry = $this->wanCache->get( $titleKey );
+
+ $curTTL = null;
+ $entry = $this->wanCache->get(
+ $titleKey,
+ $curTTL,
+ [ wfMemcKey( 'messages', $code ) ]
+ );
+ $entry = ( $curTTL >= 0 ) ? $entry : false;
+
if ( $entry ) {
if ( substr( $entry, 0, 1 ) === ' ' ) {
$this->mCache[$code][$title] = $entry;
-
- // The message exists, so make sure a string
- // is returned.
+ // The message exists, so make sure a string is returned
return (string)substr( $entry, 1 );
} elseif ( $entry === '!NONEXISTENT' ) {
$this->mCache[$code][$title] = '!NONEXISTENT';
return false;
} else {
- # Corrupt/obsolete entry, delete it
+ // Corrupt/obsolete entry, delete it
$this->wanCache->delete( $titleKey );
}
}
- # Try loading it from the database
- $revision = Revision::newFromTitle( Title::makeTitle( NS_MEDIAWIKI, $title ) );
+ // Try loading it from the database
+ $dbr = wfGetDB( DB_REPLICA );
+ $cacheOpts = Database::getCacheSetOptions( $dbr );
+ // Use newKnownCurrent() to avoid querying revision/user tables
+ $titleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
+ if ( $titleObj->getLatestRevID() ) {
+ $revision = Revision::newKnownCurrent(
+ $dbr,
+ $titleObj->getArticleID(),
+ $titleObj->getLatestRevID()
+ );
+ } else {
+ $revision = false;
+ }
+
if ( $revision ) {
$content = $revision->getContent();
if ( !$content ) {
$message = false; // negative caching
} else {
$this->mCache[$code][$title] = ' ' . $message;
- $this->wanCache->set( $titleKey, ' ' . $message, $this->mExpiry );
+ $this->wanCache->set( $titleKey, ' ' . $message, $this->mExpiry, $cacheOpts );
}
}
} else {
if ( $message === false ) { // negative caching
$this->mCache[$code][$title] = '!NONEXISTENT';
- $this->wanCache->set( $titleKey, '!NONEXISTENT', $this->mExpiry );
+ $this->wanCache->set( $titleKey, '!NONEXISTENT', $this->mExpiry, $cacheOpts );
}
return $message;