本文整理汇总了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();
});
}
示例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);
}
}
示例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));
}
示例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);
});
}
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
示例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;
}
}
示例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);
});
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}