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


PHP ObjectCache::getMainWANInstance方法代码示例

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


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

示例1: getBlackList

 public static function getBlackList()
 {
     $cache = \ObjectCache::getMainWANInstance();
     return $cache->getWithSetCallback(wfMemcKey('flowthread', 'spamblacklist'), 60, function () {
         return self::buildBlacklist();
     });
 }
开发者ID:moegirlwiki,项目名称:MW-FlowThread,代码行数:7,代码来源:SpamFilter.php

示例2: checkPurge

 /**
  * Check whether feed's cache should be cleared; for changes feeds
  * If the feed should be purged; $timekey and $key will be removed from cache
  *
  * @param string $timekey Cache key of the timestamp of the last item
  * @param string $key Cache key of feed's content
  */
 public static function checkPurge($timekey, $key)
 {
     global $wgRequest, $wgUser;
     $purge = $wgRequest->getVal('action') === 'purge';
     if ($purge && $wgUser->isAllowed('purge')) {
         $cache = ObjectCache::getMainWANInstance();
         $cache->delete($timekey, 1);
         $cache->delete($key, 1);
     }
 }
开发者ID:mb720,项目名称:mediawiki,代码行数:17,代码来源:FeedUtils.php

示例3: testGetLinkClasses

 public function testGetLinkClasses()
 {
     $wanCache = ObjectCache::getMainWANInstance();
     $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
     $linkCache = new LinkCache($titleFormatter, $wanCache);
     $foobarTitle = new TitleValue(NS_MAIN, 'FooBar');
     $redirectTitle = new TitleValue(NS_MAIN, 'Redirect');
     $userTitle = new TitleValue(NS_USER, 'Someuser');
     $linkCache->addGoodLinkObj(1, $foobarTitle, 10, 0);
     $linkCache->addGoodLinkObj(2, $redirectTitle, 10, 1);
     $linkCache->addGoodLinkObj(3, $userTitle, 10, 0);
     $linkRenderer = new LinkRenderer($titleFormatter, $linkCache);
     $linkRenderer->setStubThreshold(0);
     $this->assertEquals('', $linkRenderer->getLinkClasses($foobarTitle));
     $linkRenderer->setStubThreshold(20);
     $this->assertEquals('stub', $linkRenderer->getLinkClasses($foobarTitle));
     $linkRenderer->setStubThreshold(0);
     $this->assertEquals('mw-redirect', $linkRenderer->getLinkClasses($redirectTitle));
     $linkRenderer->setStubThreshold(20);
     $this->assertEquals('', $linkRenderer->getLinkClasses($userTitle));
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:21,代码来源:LinkRendererTest.php

示例4: invalidateImageRedirect

 /**
  * Invalidates image redirect cache related to that image
  *
  * @param Title $title Title of page
  * @return void
  */
 function invalidateImageRedirect(Title $title)
 {
     $key = $this->getSharedCacheKey('image_redirect', md5($title->getDBkey()));
     if ($key) {
         $this->getMasterDB()->onTransactionPreCommitOrIdle(function () use($key) {
             ObjectCache::getMainWANInstance()->delete($key);
         });
     }
 }
开发者ID:rugby110,项目名称:mediawiki,代码行数:15,代码来源:LocalRepo.php

示例5: getDiffBody

 /**
  * Get the diff table body, without header
  *
  * @return mixed (string/false)
  */
 public function getDiffBody()
 {
     $this->mCacheHit = true;
     // Check if the diff should be hidden from this user
     if (!$this->loadRevisionData()) {
         return false;
     } elseif ($this->mOldRev && !$this->mOldRev->userCan(Revision::DELETED_TEXT, $this->getUser())) {
         return false;
     } elseif ($this->mNewRev && !$this->mNewRev->userCan(Revision::DELETED_TEXT, $this->getUser())) {
         return false;
     }
     // Short-circuit
     if ($this->mOldRev === false || $this->mOldRev && $this->mNewRev && $this->mOldRev->getID() == $this->mNewRev->getID()) {
         return '';
     }
     // Cacheable?
     $key = false;
     $cache = ObjectCache::getMainWANInstance();
     if ($this->mOldid && $this->mNewid) {
         $key = $this->getDiffBodyCacheKey();
         // Try cache
         if (!$this->mRefreshCache) {
             $difftext = $cache->get($key);
             if ($difftext) {
                 wfIncrStats('diff_cache.hit');
                 $difftext = $this->localiseLineNumbers($difftext);
                 $difftext .= "\n<!-- diff cache key {$key} -->\n";
                 return $difftext;
             }
         }
         // don't try to load but save the result
     }
     $this->mCacheHit = false;
     // Loadtext is permission safe, this just clears out the diff
     if (!$this->loadText()) {
         return false;
     }
     $difftext = $this->generateContentDiffBody($this->mOldContent, $this->mNewContent);
     // Save to cache for 7 days
     if (!Hooks::run('AbortDiffCache', array(&$this))) {
         wfIncrStats('diff_cache.uncacheable');
     } elseif ($key !== false && $difftext !== false) {
         wfIncrStats('diff_cache.miss');
         $cache->set($key, $difftext, 7 * 86400);
     } else {
         wfIncrStats('diff_cache.uncacheable');
     }
     // Replace line numbers with the text in the user's language
     if ($difftext !== false) {
         $difftext = $this->localiseLineNumbers($difftext);
     }
     return $difftext;
 }
开发者ID:guochangjiang,项目名称:mediawiki,代码行数:58,代码来源:DifferenceEngine.php

示例6: __construct

 /**
  * @param BagOStuff $memCached A cache instance. If none, fall back to CACHE_NONE.
  * @param bool $useDB
  * @param int $expiry Lifetime for cache. @see $mExpiry.
  */
 function __construct($memCached, $useDB, $expiry)
 {
     global $wgUseLocalMessageCache;
     if (!$memCached) {
         $memCached = wfGetCache(CACHE_NONE);
     }
     $this->mMemc = $memCached;
     $this->mDisable = !$useDB;
     $this->mExpiry = $expiry;
     if ($wgUseLocalMessageCache) {
         $this->localCache = ObjectCache::newAccelerator(CACHE_NONE);
     } else {
         $this->localCache = wfGetCache(CACHE_NONE);
     }
     $this->wanCache = ObjectCache::getMainWANInstance();
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:21,代码来源:MessageCache.php

示例7: tagUsageStatistics

 /**
  * Returns a map of any tags used on the wiki to number of edits
  * tagged with them, ordered descending by the hitcount.
  * This does not include tags defined somewhere that have never been applied.
  *
  * Keeps a short-term cache in memory, so calling this multiple times in the
  * same request should be fine.
  *
  * @return array Array of string => int
  */
 public static function tagUsageStatistics()
 {
     static $cachedStats = null;
     // Process cache to avoid I/O and repeated regens during holdoff
     if ($cachedStats !== null) {
         return $cachedStats;
     }
     $fname = __METHOD__;
     $cachedStats = ObjectCache::getMainWANInstance()->getWithSetCallback(wfMemcKey('change-tag-statistics'), 300, function ($oldValue, &$ttl, array &$setOpts) use($fname) {
         $dbr = wfGetDB(DB_SLAVE, 'vslow');
         $setOpts += Database::getCacheSetOptions($dbr);
         $res = $dbr->select('change_tag', array('ct_tag', 'hitcount' => 'count(*)'), array(), $fname, array('GROUP BY' => 'ct_tag', 'ORDER BY' => 'hitcount DESC'));
         $out = array();
         foreach ($res as $row) {
             $out[$row->ct_tag] = $row->hitcount;
         }
         return $out;
     }, array('checkKeys' => array(wfMemcKey('change-tag-statistics')), 'lockTSE' => INF));
     return $cachedStats;
 }
开发者ID:agothro,项目名称:mediawiki,代码行数:30,代码来源:ChangeTags.php

示例8: __construct

 /**
  * Additional parameters include:
  *   - cluster : The name of an external cluster registered via LBFactory.
  *               If not specified, the primary DB cluster for the wiki will be used.
  *               This can be overridden with a custom cluster so that DB handles will
  *               be retrieved via LBFactory::getExternalLB() and getConnection().
  * @param array $params
  */
 protected function __construct(array $params)
 {
     parent::__construct($params);
     $this->cluster = isset($params['cluster']) ? $params['cluster'] : false;
     $this->cache = ObjectCache::getMainWANInstance();
 }
开发者ID:OrBin,项目名称:mediawiki,代码行数:14,代码来源:JobQueueDB.php

示例9: loadRestrictions

 /**
  * Load restrictions from the page_restrictions table
  *
  * @param string $oldFashionedRestrictions Comma-separated list of page
  *   restrictions from page table (pre 1.10)
  */
 public function loadRestrictions($oldFashionedRestrictions = null)
 {
     if ($this->mRestrictionsLoaded) {
         return;
     }
     $id = $this->getArticleID();
     if ($id) {
         $cache = ObjectCache::getMainWANInstance();
         $rows = $cache->getWithSetCallback($cache->makeKey('page-restrictions', $id, $this->getLatestRevID()), $cache::TTL_DAY, function ($curValue, &$ttl, array &$setOpts) {
             $dbr = wfGetDB(DB_REPLICA);
             $setOpts += Database::getCacheSetOptions($dbr);
             return iterator_to_array($dbr->select('page_restrictions', ['pr_type', 'pr_expiry', 'pr_level', 'pr_cascade'], ['pr_page' => $this->getArticleID()], __METHOD__));
         });
         $this->loadRestrictionsFromRows($rows, $oldFashionedRestrictions);
     } else {
         $title_protection = $this->getTitleProtection();
         if ($title_protection) {
             $now = wfTimestampNow();
             $expiry = wfGetDB(DB_REPLICA)->decodeExpiry($title_protection['expiry']);
             if (!$expiry || $expiry > $now) {
                 // Apply the restrictions
                 $this->mRestrictionsExpiry['create'] = $expiry;
                 $this->mRestrictions['create'] = explode(',', trim($title_protection['permission']));
             } else {
                 // Get rid of the old restrictions
                 $this->mTitleProtection = false;
             }
         } else {
             $this->mRestrictionsExpiry['create'] = 'infinity';
         }
         $this->mRestrictionsLoaded = true;
     }
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:39,代码来源:Title.php

示例10: getBlackList

 private static function getBlackList()
 {
     $cache = \ObjectCache::getMainWANInstance();
     return $cache->getWithSetCallback(wfMemcKey('flowthread', 'spamblacklist'), 60, function () {
         $source = wfMessage('flowthread-blacklist')->inContentLanguage();
         if ($source->isDisabled()) {
             return array();
         }
         $lines = explode("\n", $source->text());
         return self::parseLines($lines);
     });
 }
开发者ID:nbdd0121,项目名称:MW-FlowThread,代码行数:12,代码来源:SpamFilter.php

示例11: fetchExtendedMetadata

 /**
  * Get an array of extended metadata. (See the imageinfo API for format.)
  *
  * @param File $file File to use
  * @return array [<property name> => ['value' => <value>]], or [] on error
  * @since 1.23
  */
 public function fetchExtendedMetadata(File $file)
 {
     $cache = ObjectCache::getMainWANInstance();
     // If revision deleted, exit immediately
     if ($file->isDeleted(File::DELETED_FILE)) {
         return [];
     }
     $cacheKey = wfMemcKey('getExtendedMetadata', $this->getLanguage()->getCode(), (int) $this->singleLang, $file->getSha1());
     $cachedValue = $cache->get($cacheKey);
     if ($cachedValue && Hooks::run('ValidateExtendedMetadataCache', [$cachedValue['timestamp'], $file])) {
         $extendedMetadata = $cachedValue['data'];
     } else {
         $maxCacheTime = $file instanceof ForeignAPIFile ? 60 * 60 * 12 : 60 * 60 * 24 * 30;
         $fileMetadata = $this->getExtendedMetadataFromFile($file);
         $extendedMetadata = $this->getExtendedMetadataFromHook($file, $fileMetadata, $maxCacheTime);
         if ($this->singleLang) {
             $this->resolveMultilangMetadata($extendedMetadata);
         }
         $this->discardMultipleValues($extendedMetadata);
         // Make sure the metadata won't break the API when an XML format is used.
         // This is an API-specific function so it would be cleaner to call it from
         // outside fetchExtendedMetadata, but this way we don't need to redo the
         // computation on a cache hit.
         $this->sanitizeArrayForAPI($extendedMetadata);
         $valueToCache = ['data' => $extendedMetadata, 'timestamp' => wfTimestampNow()];
         $cache->set($cacheKey, $valueToCache, $maxCacheTime);
     }
     return $extendedMetadata;
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:36,代码来源:FormatMetadata.php

示例12: loadText

 /**
  * Lazy-load the revision's text.
  * Currently hardcoded to the 'text' table storage engine.
  *
  * @return string|bool The revision's text, or false on failure
  */
 protected function loadText()
 {
     // Caching may be beneficial for massive use of external storage
     global $wgRevisionCacheExpiry;
     $cache = ObjectCache::getMainWANInstance();
     $textId = $this->getTextId();
     $key = wfMemcKey('revisiontext', 'textid', $textId);
     if ($wgRevisionCacheExpiry) {
         $text = $cache->get($key);
         if (is_string($text)) {
             wfDebug(__METHOD__ . ": got id {$textId} from cache\n");
             return $text;
         }
     }
     // If we kept data for lazy extraction, use it now...
     if ($this->mTextRow !== null) {
         $row = $this->mTextRow;
         $this->mTextRow = null;
     } else {
         $row = null;
     }
     if (!$row) {
         // Text data is immutable; check slaves first.
         $dbr = wfGetDB(DB_SLAVE);
         $row = $dbr->selectRow('text', array('old_text', 'old_flags'), array('old_id' => $textId), __METHOD__);
     }
     // Fallback to the master in case of slave lag. Also use FOR UPDATE if it was
     // used to fetch this revision to avoid missing the row due to REPEATABLE-READ.
     $forUpdate = $this->mQueryFlags & self::READ_LOCKING == self::READ_LOCKING;
     if (!$row && ($forUpdate || wfGetLB()->getServerCount() > 1)) {
         $dbw = wfGetDB(DB_MASTER);
         $row = $dbw->selectRow('text', array('old_text', 'old_flags'), array('old_id' => $textId), __METHOD__, $forUpdate ? array('FOR UPDATE') : array());
     }
     if (!$row) {
         wfDebugLog('Revision', "No text row with ID '{$textId}' (revision {$this->getId()}).");
     }
     $text = self::getRevisionText($row);
     if ($row && $text === false) {
         wfDebugLog('Revision', "No blob for text row '{$textId}' (revision {$this->getId()}).");
     }
     # No negative caching -- negative hits on text rows may be due to corrupted slave servers
     if ($wgRevisionCacheExpiry && $text !== false) {
         $cache->set($key, $text, $wgRevisionCacheExpiry);
     }
     return $text;
 }
开发者ID:OrBin,项目名称:mediawiki,代码行数:52,代码来源:Revision.php

示例13: buildSidebar

 /**
  * Build an array that represents the sidebar(s), the navigation bar among them.
  *
  * BaseTemplate::getSidebar can be used to simplify the format and id generation in new skins.
  *
  * The format of the returned array is array( heading => content, ... ), where:
  * - heading is the heading of a navigation portlet. It is either:
  *   - magic string to be handled by the skins ('SEARCH' / 'LANGUAGES' / 'TOOLBOX' / ...)
  *   - a message name (e.g. 'navigation'), the message should be HTML-escaped by the skin
  *   - plain text, which should be HTML-escaped by the skin
  * - content is the contents of the portlet. It is either:
  *   - HTML text (<ul><li>...</li>...</ul>)
  *   - array of link data in a format accepted by BaseTemplate::makeListItem()
  *   - (for a magic string as a key, any value)
  *
  * Note that extensions can control the sidebar contents using the SkinBuildSidebar hook
  * and can technically insert anything in here; skin creators are expected to handle
  * values described above.
  *
  * @return array
  */
 function buildSidebar()
 {
     global $wgEnableSidebarCache, $wgSidebarCacheExpiry;
     $cache = ObjectCache::getMainWANInstance();
     $key = wfMemcKey('sidebar', $this->getLanguage()->getCode());
     if ($wgEnableSidebarCache) {
         $cachedsidebar = $cache->get($key);
         if ($cachedsidebar) {
             Hooks::run('SidebarBeforeOutput', array($this, &$cachedsidebar));
             return $cachedsidebar;
         }
     }
     $bar = array();
     $this->addToSidebar($bar, 'sidebar');
     Hooks::run('SkinBuildSidebar', array($this, &$bar));
     if ($wgEnableSidebarCache) {
         $cache->set($key, $bar, $wgSidebarCacheExpiry);
     }
     Hooks::run('SidebarBeforeOutput', array($this, &$bar));
     return $bar;
 }
开发者ID:junjiemars,项目名称:mediawiki,代码行数:42,代码来源:Skin.php

示例14: buildSidebar

 /**
  * Build an array that represents the sidebar(s), the navigation bar among them.
  *
  * BaseTemplate::getSidebar can be used to simplify the format and id generation in new skins.
  *
  * The format of the returned array is array( heading => content, ... ), where:
  * - heading is the heading of a navigation portlet. It is either:
  *   - magic string to be handled by the skins ('SEARCH' / 'LANGUAGES' / 'TOOLBOX' / ...)
  *   - a message name (e.g. 'navigation'), the message should be HTML-escaped by the skin
  *   - plain text, which should be HTML-escaped by the skin
  * - content is the contents of the portlet. It is either:
  *   - HTML text (<ul><li>...</li>...</ul>)
  *   - array of link data in a format accepted by BaseTemplate::makeListItem()
  *   - (for a magic string as a key, any value)
  *
  * Note that extensions can control the sidebar contents using the SkinBuildSidebar hook
  * and can technically insert anything in here; skin creators are expected to handle
  * values described above.
  *
  * @return array
  */
 function buildSidebar()
 {
     global $wgEnableSidebarCache, $wgSidebarCacheExpiry;
     $that = $this;
     $callback = function () use($that) {
         $bar = array();
         $that->addToSidebar($bar, 'sidebar');
         Hooks::run('SkinBuildSidebar', array($that, &$bar));
         return $bar;
     };
     if ($wgEnableSidebarCache) {
         $cache = ObjectCache::getMainWANInstance();
         $sidebar = $cache->getWithSetCallback($cache->makeKey('sidebar', $this->getLanguage()->getCode()), $wgSidebarCacheExpiry, $callback, array('lockTSE' => 30));
     } else {
         $sidebar = $callback();
     }
     // Apply post-processing to the cached value
     Hooks::run('SidebarBeforeOutput', array($this, &$sidebar));
     return $sidebar;
 }
开发者ID:bkmls,项目名称:mediawiki,代码行数:41,代码来源:Skin.php

示例15: __construct

 /**
  * @param BagOStuff $memCached A cache instance. If none, fall back to CACHE_NONE.
  * @param bool $useDB
  * @param int $expiry Lifetime for cache. @see $mExpiry.
  */
 function __construct($memCached, $useDB, $expiry)
 {
     global $wgUseLocalMessageCache;
     if (!$memCached) {
         $memCached = wfGetCache(CACHE_NONE);
     }
     $this->mMemc = $memCached;
     $this->mDisable = !$useDB;
     $this->mExpiry = $expiry;
     if ($wgUseLocalMessageCache) {
         $this->localCache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
     } else {
         $this->localCache = new EmptyBagOStuff();
     }
     $this->wanCache = ObjectCache::getMainWANInstance();
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:21,代码来源:MessageCache.php


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