summaryrefslogtreecommitdiff
path: root/includes/parser/ParserCache.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/parser/ParserCache.php')
-rw-r--r--includes/parser/ParserCache.php51
1 files changed, 30 insertions, 21 deletions
diff --git a/includes/parser/ParserCache.php b/includes/parser/ParserCache.php
index bc8e4a69..abff5435 100644
--- a/includes/parser/ParserCache.php
+++ b/includes/parser/ParserCache.php
@@ -26,7 +26,7 @@
* @todo document
*/
class ParserCache {
- /** @var MWMemcached */
+ /** @var BagOStuff */
private $mMemc;
/**
* Get an instance of this object
@@ -44,20 +44,19 @@ class ParserCache {
/**
* Setup a cache pathway with a given back-end storage mechanism.
- * May be a memcached client or a BagOStuff derivative.
*
- * @param MWMemcached $memCached
+ * This class use an invalidation strategy that is compatible with
+ * MultiWriteBagOStuff in async replication mode.
+ *
+ * @param BagOStuff $memCached
* @throws MWException
*/
- protected function __construct( $memCached ) {
- if ( !$memCached ) {
- throw new MWException( "Tried to create a ParserCache with an invalid memcached" );
- }
+ protected function __construct( BagOStuff $memCached ) {
$this->mMemc = $memCached;
}
/**
- * @param Article $article
+ * @param WikiPage $article
* @param string $hash
* @return mixed|string
*/
@@ -73,7 +72,7 @@ class ParserCache {
}
/**
- * @param Article $article
+ * @param WikiPage $article
* @return mixed|string
*/
protected function getOptionsKey( $article ) {
@@ -91,7 +90,7 @@ class ParserCache {
* English preferences. That's why we take into account *all* user
* options. (r70809 CR)
*
- * @param Article $article
+ * @param WikiPage $article
* @param ParserOptions $popts
* @return string
*/
@@ -103,7 +102,7 @@ class ParserCache {
/**
* Retrieve the ParserOutput from ParserCache, even if it's outdated.
- * @param Article $article
+ * @param WikiPage $article
* @param ParserOptions $popts
* @return ParserOutput|bool False on failure
*/
@@ -126,7 +125,7 @@ class ParserCache {
*
* @todo Document parameter $useOutdated
*
- * @param Article $article
+ * @param WikiPage $article
* @param ParserOptions $popts
* @param bool $useOutdated (default true)
* @return bool|mixed|string
@@ -141,15 +140,15 @@ class ParserCache {
// Determine the options which affect this article
$optionsKey = $this->mMemc->get( $this->getOptionsKey( $article ) );
- if ( $optionsKey != false ) {
+ if ( $optionsKey instanceof CacheTime ) {
if ( !$useOutdated && $optionsKey->expired( $article->getTouched() ) ) {
- wfIncrStats( "pcache_miss_expired" );
+ wfIncrStats( "pcache.miss.expired" );
$cacheTime = $optionsKey->getCacheTime();
wfDebug( "Parser options key expired, touched " . $article->getTouched()
. ", epoch $wgCacheEpoch, cached $cacheTime\n" );
return false;
} elseif ( $optionsKey->isDifferentRevision( $article->getLatest() ) ) {
- wfIncrStats( "pcache_miss_revid" );
+ wfIncrStats( "pcache.miss.revid" );
$revId = $article->getLatest();
$cachedRevId = $optionsKey->getCacheRevisionId();
wfDebug( "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId\n" );
@@ -176,7 +175,7 @@ class ParserCache {
* Retrieve the ParserOutput from ParserCache.
* false if not found or outdated.
*
- * @param Article $article
+ * @param WikiPage|Article $article
* @param ParserOptions $popts
* @param bool $useOutdated (default false)
*
@@ -195,14 +194,14 @@ class ParserCache {
$parserOutputKey = $this->getKey( $article, $popts, $useOutdated );
if ( $parserOutputKey === false ) {
- wfIncrStats( 'pcache_miss_absent' );
+ wfIncrStats( 'pcache.miss.absent' );
return false;
}
$value = $this->mMemc->get( $parserOutputKey );
if ( !$value ) {
wfDebug( "ParserOutput cache miss.\n" );
- wfIncrStats( "pcache_miss_absent" );
+ wfIncrStats( "pcache.miss.absent" );
return false;
}
@@ -213,20 +212,28 @@ class ParserCache {
// key. Force it here. See bug 31445.
$value->setEditSectionTokens( $popts->getEditSection() );
+ $wikiPage = method_exists( $article, 'getPage' )
+ ? $article->getPage()
+ : $article;
+
if ( !$useOutdated && $value->expired( $touched ) ) {
- wfIncrStats( "pcache_miss_expired" );
+ wfIncrStats( "pcache.miss.expired" );
$cacheTime = $value->getCacheTime();
wfDebug( "ParserOutput key expired, touched $touched, "
. "epoch $wgCacheEpoch, cached $cacheTime\n" );
$value = false;
} elseif ( $value->isDifferentRevision( $article->getLatest() ) ) {
- wfIncrStats( "pcache_miss_revid" );
+ wfIncrStats( "pcache.miss.revid" );
$revId = $article->getLatest();
$cachedRevId = $value->getCacheRevisionId();
wfDebug( "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId\n" );
$value = false;
+ } elseif ( Hooks::run( 'RejectParserCacheValue', array( $value, $wikiPage, $popts ) ) === false ) {
+ wfIncrStats( 'pcache.miss.rejected' );
+ wfDebug( "ParserOutput key valid, but rejected by RejectParserCacheValue hook handler.\n" );
+ $value = false;
} else {
- wfIncrStats( "pcache_hit" );
+ wfIncrStats( "pcache.hit" );
}
return $value;
@@ -276,6 +283,8 @@ class ParserCache {
// ...and its pointer
$this->mMemc->set( $this->getOptionsKey( $page ), $optionsKey, $expire );
+
+ Hooks::run( 'ParserCacheSaveComplete', array( $this, $parserOutput, $page->getTitle(), $popts, $revId ) );
} else {
wfDebug( "Parser output was marked as uncacheable and has not been saved.\n" );
}