コード例 #1
0
ファイル: ParserCache.php プロジェクト: D66Ha/mediawiki
 /**
  * Generates a key for caching the given article considering
  * the given parser options.
  *
  * @note Which parser options influence the cache key
  * is controlled via ParserOutput::recordOption() or
  * ParserOptions::addExtraKey().
  *
  * @note Used by Article to provide a unique id for the PoolCounter.
  * It would be preferable to have this code in get()
  * instead of having Article looking in our internals.
  *
  * @todo Document parameter $useOutdated
  *
  * @param WikiPage $article
  * @param ParserOptions $popts
  * @param bool $useOutdated (default true)
  * @return bool|mixed|string
  */
 public function getKey($article, $popts, $useOutdated = true)
 {
     global $wgCacheEpoch;
     if ($popts instanceof User) {
         wfWarn("Use of outdated prototype ParserCache::getKey( &\$article, &\$user )\n");
         $popts = ParserOptions::newFromUser($popts);
     }
     // Determine the options which affect this article
     $optionsKey = $this->mMemc->get($this->getOptionsKey($article));
     if ($optionsKey instanceof CacheTime) {
         if (!$useOutdated && $optionsKey->expired($article->getTouched())) {
             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");
             $revId = $article->getLatest();
             $cachedRevId = $optionsKey->getCacheRevisionId();
             wfDebug("ParserOutput key is for an old revision, latest {$revId}, cached {$cachedRevId}\n");
             return false;
         }
         // $optionsKey->mUsedOptions is set by save() by calling ParserOutput::getUsedOptions()
         $usedOptions = $optionsKey->mUsedOptions;
         wfDebug("Parser cache options found.\n");
     } else {
         if (!$useOutdated) {
             return false;
         }
         $usedOptions = ParserOptions::legacyOptions();
     }
     return $this->getParserOutputKey($article, $popts->optionsHash($usedOptions, $article->getTitle()));
 }
コード例 #2
0
 /**
  * Retrieve the ParserOutput from ParserCache.
  * false if not found or outdated.
  *
  * @param $article Article
  * @param $popts ParserOptions
  * @param $useOutdated
  *
  * @return ParserOutput|false
  */
 public function get($article, $popts, $useOutdated = false)
 {
     global $wgCacheEpoch;
     wfProfileIn(__METHOD__);
     $canCache = $article->checkTouched();
     if (!$canCache) {
         // It's a redirect now
         wfProfileOut(__METHOD__);
         return false;
     }
     $touched = $article->getTouched();
     $parserOutputKey = $this->getKey($article, $popts, $useOutdated);
     if ($parserOutputKey === false) {
         wfIncrStats('pcache_miss_absent');
         wfProfileOut(__METHOD__);
         return false;
     }
     $value = $this->mMemc->get($parserOutputKey);
     if (self::try116cache && !$value && strpos($value, '*') !== -1) {
         wfDebug("New format parser cache miss.\n");
         $parserOutputKey = $this->getParserOutputKey($article, $popts->optionsHash(ParserOptions::legacyOptions(), $article->getTitle()));
         $value = $this->mMemc->get($parserOutputKey);
     }
     if (!$value) {
         wfDebug("ParserOutput cache miss.\n");
         wfIncrStats("pcache_miss_absent");
         wfProfileOut(__METHOD__);
         return false;
     }
     wfDebug("ParserOutput cache found.\n");
     // The edit section preference may not be the appropiate one in
     // the ParserOutput, as we are not storing it in the parsercache
     // key. Force it here. See bug 31445.
     $value->setEditSectionTokens($popts->getEditSection());
     if (!$useOutdated && $value->expired($touched)) {
         wfIncrStats("pcache_miss_expired");
         $cacheTime = $value->getCacheTime();
         wfDebug("ParserOutput key expired, touched {$touched}, epoch {$wgCacheEpoch}, cached {$cacheTime}\n");
         $value = false;
     } else {
         wfIncrStats("pcache_hit");
     }
     wfProfileOut(__METHOD__);
     return $value;
 }
コード例 #3
0
	/**
	 * Get a cache key.
	 *
	 * @param $formId or null
	 * @param Parser $parser or null
	 * @return String
	 */
	public static function getCacheKey( $formId = null, &$parser = null ) {

		if ( is_null( $formId ) ) {
			return wfMemcKey( 'ext.SemanticForms.formdefinition' );
		} elseif ( is_null( $parser ) ) {
			return wfMemcKey( 'ext.SemanticForms.formdefinition', $formId );
		} else {

			if ( method_exists( 'ParserOptions', 'optionsHash' ) ) { // MW 1.17+
				$optionsHash = $parser->getOptions()->optionsHash( ParserOptions::legacyOptions() );
			} else { // MW 1.16
				$optionsHash = $parser->getOptions()->mUser->getPageRenderingHash();
			}

			return wfMemcKey(
					'ext.SemanticForms.formdefinition', $formId, $optionsHash
			);
		}
	}
コード例 #4
0
ファイル: SF_FormUtils.php プロジェクト: schwarer2006/wikia
 /**
  * Get a cache key.
  *
  * @param $formId or null
  * @param Parser $parser or null
  * @return String
  */
 public static function getCacheKey($formId = null, &$parser = null)
 {
     if (is_null($formId)) {
         return wfMemcKey('ext.SemanticForms.formdefinition');
     } elseif (is_null($parser)) {
         return wfMemcKey('ext.SemanticForms.formdefinition', $formId);
     } else {
         $optionsHash = $parser->getOptions()->optionsHash(ParserOptions::legacyOptions());
         return wfMemcKey('ext.SemanticForms.formdefinition', $formId, $optionsHash);
     }
 }
コード例 #5
0
ファイル: ParserCache.php プロジェクト: GodelDesign/Godel
 /**
  * Retrieve the ParserOutput from ParserCache.
  * false if not found or outdated.
  */
 public function get($article, $popts, $useOutdated = false)
 {
     global $wgCacheEpoch;
     wfProfileIn(__METHOD__);
     $canCache = $article->checkTouched();
     if (!$canCache) {
         // It's a redirect now
         wfProfileOut(__METHOD__);
         return false;
     }
     $touched = $article->getTouched();
     $parserOutputKey = $this->getKey($article, $popts, $useOutdated);
     if ($parserOutputKey === false) {
         wfProfileOut(__METHOD__);
         return false;
     }
     $value = $this->mMemc->get($parserOutputKey);
     if (self::try116cache && !$value && strpos($value, '*') !== -1) {
         wfDebug("New format parser cache miss.\n");
         $parserOutputKey = $this->getParserOutputKey($article, $popts->optionsHash(ParserOptions::legacyOptions()));
         $value = $this->mMemc->get($parserOutputKey);
     }
     if (!$value) {
         wfDebug("Parser cache miss.\n");
         wfIncrStats("pcache_miss_absent");
         wfProfileOut(__METHOD__);
         return false;
     }
     wfDebug("Found.\n");
     if (!$useOutdated && $value->expired($touched)) {
         wfIncrStats("pcache_miss_expired");
         $cacheTime = $value->getCacheTime();
         wfDebug("ParserOutput key expired, touched {$touched}, epoch {$wgCacheEpoch}, cached {$cacheTime}\n");
         $value = false;
     } else {
         if (isset($value->mTimestamp)) {
             $article->mTimestamp = $value->mTimestamp;
         }
         wfIncrStats("pcache_hit");
     }
     wfProfileOut(__METHOD__);
     return $value;
 }