本文整理汇总了PHP中wfGetMainCache函数的典型用法代码示例。如果您正苦于以下问题:PHP wfGetMainCache函数的具体用法?PHP wfGetMainCache怎么用?PHP wfGetMainCache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wfGetMainCache函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createCache
function createCache()
{
if (!isset($this->cache)) {
global $wgPageAttachment_useInternalCache;
global $wgPageAttachment_internalCacheType;
if (isset($wgPageAttachment_useInternalCache) && $wgPageAttachment_useInternalCache == true) {
if (isset($wgPageAttachment_internalCacheType)) {
if ($wgPageAttachment_internalCacheType == 'SQLite3') {
$this->cache = new Provider\SQLiteCache();
} else {
if ($wgPageAttachment_internalCacheType == 'Database') {
$this->cache = new Provider\DatabaseCache();
} else {
print '<br/>*** ERROR ***************************************************************<br/>';
print 'PageAttachment internal cache is enabled.<br/>';
print 'However, invalid PageAttachment internal cache type specified: ' . $wgPageAttachment_internalCacheType . '<br/>';
print '*************************************************************************<br/>';
}
}
} else {
print '<br/>*** ERROR ***************************************************************<br/>';
print 'PageAttachment internal cache is enabled.<br/>';
print 'However, PageAttachment internal cache type is not specified.<br/>';
print '*************************************************************************<br/>';
}
} else {
$mwCacheObj = \wfGetMainCache();
$this->cache = new Provider\MWCacheObjWrapper($mwCacheObj);
}
}
return $this->cache;
}
示例2: __construct
/**
* @params include:
* - objectCache : Name of an object cache registered in $wgObjectCaches.
* This defaults to the one specified by $wgMainCacheType.
* - cacheTTL : Seconds to cache the aggregate data before regenerating.
* @param array $params
*/
protected function __construct(array $params)
{
parent::__construct($params);
$this->cache = isset($params['objectCache']) ? wfGetCache($params['objectCache']) : wfGetMainCache();
$this->cacheTTL = isset($params['cacheTTL']) ? $params['cacheTTL'] : 180;
// 3 min
}
示例3: __construct
public function __construct($parent)
{
global $wgMemc;
$this->parent = $parent;
$this->srvCache = ObjectCache::newAccelerator(array(), 'hash');
$this->mainCache = $wgMemc ?: wfGetMainCache();
}
示例4: __construct
/**
* Construct a new instance from configuration.
*
* $config paramaters include:
* 'dbServers' : Associative array of DB names to server configuration.
* Configuration is an associative array that includes:
* 'host' - DB server name
* 'dbname' - DB name
* 'type' - DB type (mysql,postgres,...)
* 'user' - DB user
* 'password' - DB user password
* 'tablePrefix' - DB table prefix
* 'flags' - DB flags (see DatabaseBase)
* 'dbsByBucket' : Array of 1-16 consecutive integer keys, starting from 0,
* each having an odd-numbered list of DB names (peers) as values.
* Any DB named 'localDBMaster' will automatically use the DB master
* settings for this wiki (without the need for a dbServers entry).
* 'lockExpiry' : Lock timeout (seconds) for dropped connections. [optional]
* This tells the DB server how long to wait before assuming
* connection failure and releasing all the locks for a session.
*
* @param Array $config
*/
public function __construct(array $config)
{
$this->dbServers = isset($config['dbServers']) ? $config['dbServers'] : array();
// likely just using 'localDBMaster'
// Sanitize dbsByBucket config to prevent PHP errors
$this->dbsByBucket = array_filter($config['dbsByBucket'], 'is_array');
$this->dbsByBucket = array_values($this->dbsByBucket);
// consecutive
if (isset($config['lockExpiry'])) {
$this->lockExpiry = $config['lockExpiry'];
} else {
$met = ini_get('max_execution_time');
$this->lockExpiry = $met ? $met : 60;
// use some sane amount if 0
}
$this->safeDelay = $this->lockExpiry <= 0 ? 60 : $this->lockExpiry;
// cover worst case
foreach ($this->dbsByBucket as $bucket) {
if (count($bucket) > 1) {
// Tracks peers that couldn't be queried recently to avoid lengthy
// connection timeouts. This is useless if each bucket has one peer.
$this->statusCache = wfGetMainCache();
break;
}
}
$this->session = '';
for ($i = 0; $i < 5; $i++) {
$this->session .= mt_rand(0, 2147483647);
}
$this->session = wfBaseConvert(sha1($this->session), 16, 36, 31);
}
示例5: setUp
function setUp()
{
global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo, $parserMemc, $wgThumbnailScriptPath, $wgScriptPath, $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
$wgScript = '/index.php';
$wgScriptPath = '/';
$wgArticlePath = '/wiki/$1';
$wgStyleSheetPath = '/skins';
$wgStylePath = '/skins';
$wgThumbnailScriptPath = false;
$wgLocalFileRepo = array('class' => 'LocalRepo', 'name' => 'local', 'directory' => wfTempDir() . '/test-repo', 'url' => 'http://example.com/images', 'deletedDir' => wfTempDir() . '/test-repo/delete', 'hashLevels' => 2, 'transformVia404' => false);
$wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
$wgNamespaceAliases['Image'] = NS_FILE;
$wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
$wgEnableParserCache = false;
$wgDeferredUpdateList = array();
$wgMemc = wfGetMainCache();
$messageMemc = wfGetMessageCacheStorage();
$parserMemc = wfGetParserCacheStorage();
// $wgContLang = new StubContLang;
$wgUser = new User();
$context = new RequestContext();
$wgLang = $context->getLang();
$wgOut = $context->getOutput();
$wgParser = new StubObject('wgParser', $wgParserConf['class'], array($wgParserConf));
$wgRequest = new WebRequest();
if ($wgStyleDirectory === false) {
$wgStyleDirectory = "{$IP}/skins";
}
}
示例6: newInstance
/**
* @since 1.21
* @deprecated 1.25 Construct a SiteStore instance directly instead.
*
* @param ORMTable|null $sitesTable
* @param BagOStuff|null $cache
*
* @return SiteStore
*/
public static function newInstance(ORMTable $sitesTable = null, BagOStuff $cache = null)
{
if ($cache === null) {
$cache = wfGetMainCache();
}
$siteStore = new DBSiteStore();
return new static($siteStore, $cache);
}
示例7: init
/**
* Initialization
*/
private static function init()
{
clearstatcache();
self::$cache =& wfGetMainCache();
if (self::$cache instanceof FakeMemCachedClient) {
self::$realCache = false;
}
}
示例8: execute
public function execute()
{
$force = $this->getOption('force', false);
$this->source = $this->getOption('source', 'https://en.wikipedia.org/w/api.php');
$this->cache = wfGetMainCache();
$data = $this->fetchLinks();
if ($data === false) {
$this->error("Error during fetching data.");
} else {
$this->doPopulate($data, $force);
}
}
示例9: setUp
function setUp()
{
global $wgContLang, $wgNamespaceProtection, $wgNamespaceAliases;
global $wgHooks, $IP;
$wgContLang = Language::factory('en');
//Setup CLI arguments
if ($this->getCliArg('regex=')) {
$this->regex = $this->getCliArg('regex=');
} else {
# Matches anything
$this->regex = '';
}
$this->keepUploads = $this->getCliArg('keep-uploads');
$tmpGlobals = array();
$tmpGlobals['wgScript'] = '/index.php';
$tmpGlobals['wgScriptPath'] = '/';
$tmpGlobals['wgArticlePath'] = '/wiki/$1';
$tmpGlobals['wgStyleSheetPath'] = '/skins';
$tmpGlobals['wgStylePath'] = '/skins';
$tmpGlobals['wgThumbnailScriptPath'] = false;
$tmpGlobals['wgLocalFileRepo'] = array('class' => 'LocalRepo', 'name' => 'local', 'url' => 'http://example.com/images', 'hashLevels' => 2, 'transformVia404' => false, 'backend' => 'local-backend');
$tmpGlobals['wgForeignFileRepos'] = array();
$tmpGlobals['wgEnableParserCache'] = false;
$tmpGlobals['wgHooks'] = $wgHooks;
$tmpGlobals['wgDeferredUpdateList'] = array();
$tmpGlobals['wgMemc'] = wfGetMainCache();
$tmpGlobals['messageMemc'] = wfGetMessageCacheStorage();
$tmpGlobals['parserMemc'] = wfGetParserCacheStorage();
// $tmpGlobals['wgContLang'] = new StubContLang;
$tmpGlobals['wgUser'] = new User();
$context = new RequestContext();
$tmpGlobals['wgLang'] = $context->getLanguage();
$tmpGlobals['wgOut'] = $context->getOutput();
$tmpGlobals['wgParser'] = new StubObject('wgParser', $GLOBALS['wgParserConf']['class'], array($GLOBALS['wgParserConf']));
$tmpGlobals['wgRequest'] = $context->getRequest();
if ($GLOBALS['wgStyleDirectory'] === false) {
$tmpGlobals['wgStyleDirectory'] = "{$IP}/skins";
}
foreach ($tmpGlobals as $var => $val) {
if (array_key_exists($var, $GLOBALS)) {
$this->savedInitialGlobals[$var] = $GLOBALS[$var];
}
$GLOBALS[$var] = $val;
}
$this->savedWeirdGlobals['mw_namespace_protection'] = $wgNamespaceProtection[NS_MEDIAWIKI];
$this->savedWeirdGlobals['image_alias'] = $wgNamespaceAliases['Image'];
$this->savedWeirdGlobals['image_talk_alias'] = $wgNamespaceAliases['Image_talk'];
$wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
$wgNamespaceAliases['Image'] = NS_FILE;
$wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
}
示例10: getLagTimes
function getLagTimes($serverIndexes, $wiki)
{
wfProfileIn(__METHOD__);
$expiry = 5;
$requestRate = 10;
global $wgMemc;
if (empty($wgMemc)) {
$wgMemc = wfGetMainCache();
}
$masterName = $this->parent->getServerName(0);
$memcKey = wfMemcKey('lag_times', $masterName);
$times = $wgMemc->get($memcKey);
if ($times) {
# Randomly recache with probability rising over $expiry
$elapsed = time() - $times['timestamp'];
$chance = max(0, ($expiry - $elapsed) * $requestRate);
if (mt_rand(0, $chance) != 0) {
unset($times['timestamp']);
wfProfileOut(__METHOD__);
return $times;
}
wfIncrStats('lag_cache_miss_expired');
} else {
wfIncrStats('lag_cache_miss_absent');
}
# Cache key missing or expired
$times = array();
foreach ($serverIndexes as $i) {
if ($i == 0) {
# Master
$times[$i] = 0;
} elseif (false !== ($conn = $this->parent->getAnyOpenConnection($i))) {
$times[$i] = $conn->getLag();
} elseif (false !== ($conn = $this->parent->openConnection($i, $wiki))) {
$times[$i] = $conn->getLag();
}
}
# Add a timestamp key so we know when it was cached
$times['timestamp'] = time();
$wgMemc->set($memcKey, $times, $expiry);
# But don't give the timestamp to the caller
unset($times['timestamp']);
$lagTimes = $times;
wfProfileOut(__METHOD__);
return $lagTimes;
}
示例11: suite
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite();
self::$iter = new TestFileIterator(PARSER_TESTS);
foreach (self::$iter as $i => $test) {
$suite->addTest(new ParserUnitTest($i, $test['test']));
self::$count++;
}
unset($tests);
self::$parser = new PTShell();
self::$iter->setParser(self::$parser);
self::$parser->recorder->start();
self::$parser->setupDatabase();
self::$iter->rewind();
/* } */
/* function setUp() { */
global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc, $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo, $wgNamespacesWithSubpages, $wgThumbnailScriptPath, $wgScriptPath, $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
$wgScript = '/index.php';
$wgScriptPath = '/';
$wgArticlePath = '/wiki/$1';
$wgStyleSheetPath = '/skins';
$wgStylePath = '/skins';
$wgThumbnailScriptPath = false;
$wgLocalFileRepo = array('class' => 'LocalRepo', 'name' => 'local', 'directory' => '', 'url' => 'http://example.com/images', 'hashLevels' => 2, 'transformVia404' => false);
$wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
$wgNamespaceAliases['Image'] = NS_FILE;
$wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
$wgEnableParserCache = false;
$wgDeferredUpdateList = array();
$wgMemc =& wfGetMainCache();
$messageMemc =& wfGetMessageCacheStorage();
$parserMemc =& wfGetParserCacheStorage();
$wgContLang = new StubContLang();
$wgUser = new StubUser();
$wgLang = new StubUserLang();
$wgOut = new StubObject('wgOut', 'OutputPage');
$wgParser = new StubObject('wgParser', $wgParserConf['class'], array($wgParserConf));
$wgRequest = new WebRequest();
$wgMessageCache = new StubObject('wgMessageCache', 'MessageCache', array($messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID()));
if ($wgStyleDirectory === false) {
$wgStyleDirectory = "{$IP}/skins";
}
return $suite;
}
示例12: setUp
protected function setUp()
{
global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgParserCacheType, $wgNamespaceAliases, $wgNamespaceProtection, $parserMemc;
$tmpDir = $this->getNewTempDirectory();
$tmpGlobals = [];
$tmpGlobals['wgScript'] = '/index.php';
$tmpGlobals['wgScriptPath'] = '/';
$tmpGlobals['wgArticlePath'] = '/wiki/$1';
$tmpGlobals['wgStylePath'] = '/skins';
$tmpGlobals['wgThumbnailScriptPath'] = false;
$tmpGlobals['wgLocalFileRepo'] = ['class' => 'LocalRepo', 'name' => 'local', 'url' => 'http://example.com/images', 'hashLevels' => 2, 'transformVia404' => false, 'backend' => new FSFileBackend(['name' => 'local-backend', 'wikiId' => wfWikiID(), 'containerPaths' => ['local-public' => "{$tmpDir}/test-repo/public", 'local-thumb' => "{$tmpDir}/test-repo/thumb", 'local-temp' => "{$tmpDir}/test-repo/temp", 'local-deleted' => "{$tmpDir}/test-repo/delete"]])];
foreach ($tmpGlobals as $var => $val) {
if (array_key_exists($var, $GLOBALS)) {
$this->savedGlobals[$var] = $GLOBALS[$var];
}
$GLOBALS[$var] = $val;
}
$wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
$wgNamespaceAliases['Image'] = NS_FILE;
$wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
$wgParserCacheType = CACHE_NONE;
DeferredUpdates::clearPendingUpdates();
$wgMemc = wfGetMainCache();
$messageMemc = wfGetMessageCacheStorage();
$parserMemc = wfGetParserCacheStorage();
RequestContext::resetMain();
$context = RequestContext::getMain();
$wgUser = new User();
$wgLang = $context->getLanguage();
$wgOut = $context->getOutput();
$wgParser = new StubObject('wgParser', $wgParserConf['class'], [$wgParserConf]);
$wgRequest = $context->getRequest();
if ($wgStyleDirectory === false) {
$wgStyleDirectory = "{$IP}/skins";
}
RepoGroup::destroySingleton();
FileBackendGroup::destroySingleton();
}
示例13: __construct
public function __construct()
{
global $IP;
// No Setup.php yet. Initialise everything by ourselves
require_once $IP . '/includes/GlobalFunctions.php';
require_once $IP . '/includes/ObjectCache.php';
$wgMemc = wfGetMainCache();
// Caching not yet working
$cached = false;
//$wgMemc->get( 'configurewmf:data' );
if ($cached) {
$this->overrides = $cached;
return;
}
$dbr = self::getSlaveDB();
$r = $dbr->select('config_overrides', array('cfg_target', 'cfg_value'), null, __METHOD__);
$overrides = array();
while ($row = $dbr->fetchObject($r)) {
$overrides[] = array('target' => $row->cfg_target, 'value' => unserialize($row->cfg_value));
}
$wgMemc->set('configurewmf:data', $overrides);
$this->overrides = $overrides;
}
示例14: __construct
/**
* @see FileBackendStore::__construct()
* Additional $config params include:
* swiftAuthUrl : Swift authentication server URL
* swiftUser : Swift user used by MediaWiki (account:username)
* swiftKey : Swift authentication key for the above user
* swiftAuthTTL : Swift authentication TTL (seconds)
* swiftAnonUser : Swift user used for end-user requests (account:username)
* shardViaHashLevels : Map of container names to sharding config with:
* 'base' : base of hash characters, 16 or 36
* 'levels' : the number of hash levels (and digits)
* 'repeat' : hash subdirectories are prefixed with all the
* parent hash directory names (e.g. "a/ab/abc")
* swiftTimeout : number of seconds timeout consistent with php-cloudfiles. Default: 10
*/
public function __construct(array $config)
{
parent::__construct($config);
// Required settings
$this->auth = new CF_Authentication($config['swiftUser'], $config['swiftKey'], null, $config['swiftAuthUrl']);
/* <Wikia> */
if (!empty($config['debug'])) {
$this->auth->setDebug($config['debug']);
}
$this->swiftTimeout = isset($config['swiftTimeout']) ? intval($config['swiftTimeout']) : 10;
/* </Wikia> */
// Optional settings
$this->authTTL = isset($config['swiftAuthTTL']) ? $config['swiftAuthTTL'] : 120;
// some sane number
$this->swiftAnonUser = isset($config['swiftAnonUser']) ? $config['swiftAnonUser'] : '';
$this->shardViaHashLevels = isset($config['shardViaHashLevels']) ? $config['shardViaHashLevels'] : '';
/* <Wikia> */
// caching credentials
if (!empty($config['cacheAuthInfo']) && $config['cacheAuthInfo'] === true) {
$this->srvCache = wfGetMainCache();
}
$this->srvCache = $this->srvCache ? $this->srvCache : new EmptyBagOStuff();
/* </Wikia> */
}
示例15: reset
/**
* Purges the internal and external cache of the site list, forcing the list
* of sites to be re-read from the database.
*
* @since 1.21
*/
public function reset()
{
wfProfileIn(__METHOD__);
// purge cache
$cache = wfGetMainCache();
$cache->delete($this->getCacheKey());
$this->sites = null;
wfProfileOut(__METHOD__);
}