当前位置: 首页>>代码示例>>PHP>>正文


PHP ParserOutput::setCacheTime方法代码示例

本文整理汇总了PHP中ParserOutput::setCacheTime方法的典型用法代码示例。如果您正苦于以下问题:PHP ParserOutput::setCacheTime方法的具体用法?PHP ParserOutput::setCacheTime怎么用?PHP ParserOutput::setCacheTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParserOutput的用法示例。


在下文中一共展示了ParserOutput::setCacheTime方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 /**
  * @param ParserOutput $parserOutput
  * @param WikiPage $page
  * @param ParserOptions $popts
  * @param string $cacheTime Time when the cache was generated
  * @param int $revId Revision ID that was parsed
  */
 public function save($parserOutput, $page, $popts, $cacheTime = null, $revId = null)
 {
     $expire = $parserOutput->getCacheExpiry();
     if ($expire > 0) {
         $cacheTime = $cacheTime ?: wfTimestampNow();
         if (!$revId) {
             $revision = $page->getRevision();
             $revId = $revision ? $revision->getId() : null;
         }
         $optionsKey = new CacheTime();
         $optionsKey->mUsedOptions = $parserOutput->getUsedOptions();
         $optionsKey->updateCacheExpiry($expire);
         $optionsKey->setCacheTime($cacheTime);
         $parserOutput->setCacheTime($cacheTime);
         $optionsKey->setCacheRevisionId($revId);
         $parserOutput->setCacheRevisionId($revId);
         $parserOutputKey = $this->getParserOutputKey($page, $popts->optionsHash($optionsKey->mUsedOptions, $page->getTitle()));
         // Save the timestamp so that we don't have to load the revision row on view
         $parserOutput->setTimestamp($page->getTimestamp());
         $msg = "Saved in parser cache with key {$parserOutputKey}" . " and timestamp {$cacheTime}" . " and revision id {$revId}" . "\n";
         $parserOutput->mText .= "\n<!-- {$msg} -->\n";
         wfDebug($msg);
         // Save the parser output
         $this->mMemc->set($parserOutputKey, $parserOutput, $expire);
         // ...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");
     }
 }
开发者ID:D66Ha,项目名称:mediawiki,代码行数:38,代码来源:ParserCache.php

示例2: disableCache

 /**
  * Set a flag in the output object indicating that the content is dynamic and
  * shouldn't be cached.
  */
 function disableCache()
 {
     wfDebug("Parser output marked as uncacheable.\n");
     if (!$this->mOutput) {
         throw new MWException(__METHOD__ . " can only be called when actually parsing something");
     }
     $this->mOutput->setCacheTime(-1);
     // old style, for compatibility
     $this->mOutput->updateCacheExpiry(0);
     // new style, for consistency
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:15,代码来源:Parser.php

示例3: disableCache

 /**
  * Set a flag in the output object indicating that the content is dynamic and
  * shouldn't be cached.
  */
 function disableCache()
 {
     wfDebug("Parser output marked as uncacheable.\n");
     $this->mOutput->setCacheTime(-1);
     // old style, for compatibility
     $this->mOutput->updateCacheExpiry(0);
     // new style, for consistency
 }
开发者ID:eFFemeer,项目名称:seizamcore,代码行数:12,代码来源:Parser.php

示例4: disableCache

 /**
  * Set a flag in the output object indicating that the content is dynamic and
  * shouldn't be cached.
  */
 function disableCache()
 {
     wfDebug("Parser output marked as uncacheable.\n");
     if (!$this->mOutput) {
         throw new MWException(__METHOD__ . " can only be called when actually parsing something");
     }
     $this->mOutput->setCacheTime(-1);
     // old style, for compatibility
     $this->mOutput->updateCacheExpiry(0);
     // new style, for consistency
     // Wikia change - begin
     Wikia\Logger\WikiaLogger::instance()->info(__METHOD__, ['exception' => new Exception()]);
     Transaction::setAttribute(Transaction::PARAM_PARSER_CACHE_DISABLED, true);
     // Wikia change - end
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:19,代码来源:Parser.php

示例5: save

 /**
  * @param $parserOutput ParserOutput
  * @param $article Page
  * @param $popts ParserOptions
  */
 public function save(ParserOutput $parserOutput, Page $article, ParserOptions $popts)
 {
     wfRunHooks('BeforeParserCacheSave', [$parserOutput, $article]);
     $expire = $parserOutput->getCacheExpiry();
     if ($expire > 0) {
         $now = wfTimestampNow();
         $optionsKey = new CacheTime();
         $optionsKey->mUsedOptions = $parserOutput->getUsedOptions();
         $optionsKey->updateCacheExpiry($expire);
         $optionsKey->setCacheTime($now);
         $parserOutput->setCacheTime($now);
         $optionsKey->setContainsOldMagic($parserOutput->containsOldMagic());
         $parserOutputKey = $this->getParserOutputKey($article, $popts->optionsHash($optionsKey->mUsedOptions, $article->getTitle()));
         // Save the timestamp so that we don't have to load the revision row on view
         $parserOutput->setTimestamp($article->getTimestamp());
         // Wikia change - begin
         // @author macbre - BAC-1172
         #$info = "Saved in parser cache with key $parserOutputKey and timestamp $now";
         global $wgArticleAsJson;
         if (!$wgArticleAsJson) {
             $info = "Saved in parser cache with key {$parserOutputKey}";
             $parserOutput->mText .= "\n<!-- {$info} -->\n";
         }
         wfDebug("{$info}\n");
         // Wikia change - end
         // Save the parser output
         $this->mMemc->set($parserOutputKey, $parserOutput, $expire);
         // ...and its pointer
         $this->mMemc->set($this->getOptionsKey($article), $optionsKey, $expire);
     } else {
         wfDebug("Parser output was marked as uncacheable and has not been saved.\n");
     }
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:38,代码来源:ParserCache.php

示例6: stashEditFromPreview

 /**
  * Attempt to cache PST content and corresponding parser output in passing
  *
  * This method can be called when the output was already generated for other
  * reasons. Parsing should not be done just to call this method, however.
  * $pstOpts must be that of the user doing the edit preview. If $pOpts does
  * not match the options of WikiPage::makeParserOptions( 'canonical' ), this
  * will do nothing. Provided the values are cacheable, they will be stored
  * in memcached so that final edit submission might make use of them.
  *
  * @param Page|Article|WikiPage $page Page title
  * @param Content $content Proposed page content
  * @param Content $pstContent The result of preSaveTransform() on $content
  * @param ParserOutput $pOut The result of getParserOutput() on $pstContent
  * @param ParserOptions $pstOpts Options for $pstContent (MUST be for prospective author)
  * @param ParserOptions $pOpts Options for $pOut
  * @param string $timestamp TS_MW timestamp of parser output generation
  * @return bool Success
  */
 public static function stashEditFromPreview(Page $page, Content $content, Content $pstContent, ParserOutput $pOut, ParserOptions $pstOpts, ParserOptions $pOpts, $timestamp)
 {
     $cache = ObjectCache::getLocalClusterInstance();
     $logger = LoggerFactory::getInstance('StashEdit');
     // getIsPreview() controls parser function behavior that references things
     // like user/revision that don't exists yet. The user/text should already
     // be set correctly by callers, just double check the preview flag.
     if (!$pOpts->getIsPreview()) {
         return false;
         // sanity
     } elseif ($pOpts->getIsSectionPreview()) {
         return false;
         // short-circuit (need the full content)
     }
     // PST parser options are for the user (handles signatures, etc...)
     $user = $pstOpts->getUser();
     // Get a key based on the source text, format, and user preferences
     $key = self::getStashKey($page->getTitle(), $content, $user);
     // Parser output options must match cannonical options.
     // Treat some options as matching that are different but don't matter.
     $canonicalPOpts = $page->makeParserOptions('canonical');
     $canonicalPOpts->setIsPreview(true);
     // force match
     $canonicalPOpts->setTimestamp($pOpts->getTimestamp());
     // force match
     if (!$pOpts->matches($canonicalPOpts)) {
         $logger->info("Uncacheable preview output for key '{$key}' (options).");
         return false;
     }
     // Set the time the output was generated
     $pOut->setCacheTime(wfTimestampNow());
     // Build a value to cache with a proper TTL
     list($stashInfo, $ttl) = self::buildStashValue($pstContent, $pOut, $timestamp, $user);
     if (!$stashInfo) {
         $logger->info("Uncacheable parser output for key '{$key}' (rev/TTL).");
         return false;
     }
     $ok = $cache->set($key, $stashInfo, $ttl);
     if (!$ok) {
         $logger->error("Failed to cache preview parser output for key '{$key}'.");
     } else {
         $logger->debug("Cached preview output for key '{$key}'.");
     }
     return $ok;
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:64,代码来源:ApiStashEdit.php

示例7: save

 /**
  * @param ParserOutput $parserOutput
  * @param WikiPage $page
  * @param ParserOptions $popts
  * @param string $cacheTime Time when the cache was generated
  */
 public function save($parserOutput, $page, $popts, $cacheTime = null)
 {
     $expire = $parserOutput->getCacheExpiry();
     if ($expire > 0) {
         $cacheTime = $cacheTime ?: wfTimestampNow();
         $optionsKey = new CacheTime();
         $optionsKey->mUsedOptions = $parserOutput->getUsedOptions();
         $optionsKey->updateCacheExpiry($expire);
         $optionsKey->setCacheTime($cacheTime);
         $parserOutput->setCacheTime($cacheTime);
         $optionsKey->setContainsOldMagic($parserOutput->containsOldMagic());
         $parserOutputKey = $this->getParserOutputKey($page, $popts->optionsHash($optionsKey->mUsedOptions, $page->getTitle()));
         // Save the timestamp so that we don't have to load the revision row on view
         $parserOutput->setTimestamp($page->getTimestamp());
         $parserOutput->mText .= "\n<!-- Saved in parser cache with key {$parserOutputKey} and timestamp {$cacheTime}\n -->\n";
         wfDebug("Saved in parser cache with key {$parserOutputKey} and timestamp {$cacheTime}\n");
         // Save the parser output
         $this->mMemc->set($parserOutputKey, $parserOutput, $expire);
         // ...and its pointer
         $this->mMemc->set($this->getOptionsKey($page), $optionsKey, $expire);
     } else {
         wfDebug("Parser output was marked as uncacheable and has not been saved.\n");
     }
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:30,代码来源:ParserCache.php


注:本文中的ParserOutput::setCacheTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。