Merge "tests: Remove unused $wgMemc resets"
[lhc/web/wiklou.git] / includes / parser / ParserCache.php
index 47fcd30..0eba166 100644 (file)
@@ -44,15 +44,14 @@ class ParserCache {
 
        /**
         * Setup a cache pathway with a given back-end storage mechanism.
-        * May be a memcached client or a BagOStuff derivative.
+        *
+        * 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;
        }
 
@@ -140,7 +139,9 @@ class ParserCache {
                }
 
                // Determine the options which affect this article
-               $optionsKey = $this->mMemc->get( $this->getOptionsKey( $article ) );
+               $casToken = null;
+               $optionsKey = $this->mMemc->get(
+                       $this->getOptionsKey( $article ), $casToken, BagOStuff::READ_VERIFIED );
                if ( $optionsKey instanceof CacheTime ) {
                        if ( !$useOutdated && $optionsKey->expired( $article->getTouched() ) ) {
                                wfIncrStats( "pcache.miss.expired" );
@@ -199,7 +200,8 @@ class ParserCache {
                        return false;
                }
 
-               $value = $this->mMemc->get( $parserOutputKey );
+               $casToken = null;
+               $value = $this->mMemc->get( $parserOutputKey, $casToken, BagOStuff::READ_VERIFIED );
                if ( !$value ) {
                        wfDebug( "ParserOutput cache miss.\n" );
                        wfIncrStats( "pcache.miss.absent" );
@@ -227,11 +229,17 @@ class ParserCache {
                        wfIncrStats( "pcache.miss.revid" );
                        $revId = $article->getLatest();
                        $cachedRevId = $value->getCacheRevisionId();
-                       wfDebug( "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId\n" );
+                       wfDebug(
+                               "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId\n"
+                       );
                        $value = false;
-               } elseif ( Hooks::run( 'RejectParserCacheValue', array( $value, $wikiPage, $popts ) ) === 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" );
+                       wfDebug(
+                               "ParserOutput key valid, but rejected by RejectParserCacheValue hook handler.\n"
+                       );
                        $value = false;
                } else {
                        wfIncrStats( "pcache.hit" );
@@ -285,7 +293,10 @@ class ParserCache {
                        // ...and its pointer
                        $this->mMemc->set( $this->getOptionsKey( $page ), $optionsKey, $expire );
 
-                       Hooks::run( 'ParserCacheSaveComplete', array( $this, $parserOutput, $page->getTitle(), $popts, $revId ) );
+                       Hooks::run(
+                               'ParserCacheSaveComplete',
+                               array( $this, $parserOutput, $page->getTitle(), $popts, $revId )
+                       );
                } else {
                        wfDebug( "Parser output was marked as uncacheable and has not been saved.\n" );
                }