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


PHP BagOStuff::set方法代码示例

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


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

示例1: set

 public function set($key, $value, $exptime = 0, $flags = 0)
 {
     parent::set($key, $value, $exptime, $flags);
     if (!($flags & self::WRITE_CACHE_ONLY)) {
         $this->backend->set($key, $value, $exptime, $flags & ~self::WRITE_CACHE_ONLY);
     }
     return true;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:8,代码来源:CachedBagOStuff.php

示例2: doGetAllReadyWikiQueues

 /**
  * @see JobQueueAggregator::doAllGetReadyWikiQueues()
  */
 protected function doGetAllReadyWikiQueues()
 {
     $key = $this->getReadyQueueCacheKey();
     // If the cache entry wasn't present, is stale, or in .1% of cases otherwise,
     // regenerate the cache. Use any available stale cache if another process is
     // currently regenerating the pending DB information.
     $pendingDbInfo = $this->cache->get($key);
     if (!is_array($pendingDbInfo) || time() - $pendingDbInfo['timestamp'] > $this->cacheTTL || mt_rand(0, 999) == 0) {
         if ($this->cache->add("{$key}:rebuild", 1, 1800)) {
             // lock
             $pendingDbInfo = array('pendingDBs' => $this->findPendingWikiQueues(), 'timestamp' => time());
             for ($attempts = 1; $attempts <= 25; ++$attempts) {
                 if ($this->cache->add("{$key}:lock", 1, 60)) {
                     // lock
                     $this->cache->set($key, $pendingDbInfo);
                     $this->cache->delete("{$key}:lock");
                     // unlock
                     break;
                 }
             }
             $this->cache->delete("{$key}:rebuild");
             // unlock
         }
     }
     return is_array($pendingDbInfo) ? $pendingDbInfo['pendingDBs'] : array();
     // cache is both empty and locked
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:30,代码来源:JobQueueAggregatorMemc.php

示例3: 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:ngertrudiz,项目名称:mediawiki,代码行数:38,代码来源:ParserCache.php

示例4: doPop

	protected function doPop() {
		$key = $this->getCacheKey( 'empty' );

		$isEmpty = $this->cache->get( $key );
		if ( $isEmpty === 'true' ) {
			return false;
		}

		$partitionsTry = $this->partitionMap; // (partition => weight)

		while ( count( $partitionsTry ) ) {
			$partition = ArrayUtils::pickRandom( $partitionsTry );
			if ( $partition === false ) {
				break; // all partitions at 0 weight
			}
			$queue = $this->partitionQueues[$partition];
			try {
				$job = $queue->pop();
			} catch ( JobQueueError $e ) {
				$job = false;
				MWExceptionHandler::logException( $e );
			}
			if ( $job ) {
				$job->metadata['QueuePartition'] = $partition;
				return $job;
			} else {
				unset( $partitionsTry[$partition] ); // blacklist partition
			}
		}

		$this->cache->set( $key, 'true', JobQueueDB::CACHE_TTL_LONG );
		return false;
	}
开发者ID:nahoj,项目名称:mediawiki_ynh,代码行数:33,代码来源:JobQueueFederated.php

示例5: doPop

 protected function doPop()
 {
     $partitionsTry = $this->partitionRing->getLiveLocationWeights();
     // (partition => weight)
     $failed = 0;
     while (count($partitionsTry)) {
         $partition = ArrayUtils::pickRandom($partitionsTry);
         if ($partition === false) {
             break;
             // all partitions at 0 weight
         }
         /** @var JobQueue $queue */
         $queue = $this->partitionQueues[$partition];
         try {
             $job = $queue->pop();
         } catch (JobQueueError $e) {
             ++$failed;
             MWExceptionHandler::logException($e);
             $job = false;
         }
         if ($job) {
             $job->metadata['QueuePartition'] = $partition;
             return $job;
         } else {
             unset($partitionsTry[$partition]);
             // blacklist partition
         }
     }
     $this->throwErrorIfAllPartitionsDown($failed);
     $key = $this->getCacheKey('empty');
     $this->cache->set($key, 'true', self::CACHE_TTL_LONG);
     return false;
 }
开发者ID:whysasse,项目名称:kmwiki,代码行数:33,代码来源:JobQueueFederated.php

示例6: recycleAndDeleteStaleJobs

 /**
  * Recycle or destroy any jobs that have been claimed for too long
  *
  * @return int Number of jobs recycled/deleted
  */
 public function recycleAndDeleteStaleJobs()
 {
     $now = time();
     $count = 0;
     // affected rows
     $dbw = $this->getMasterDB();
     try {
         if (!$dbw->lock("jobqueue-recycle-{$this->type}", __METHOD__, 1)) {
             return $count;
             // already in progress
         }
         // Remove claims on jobs acquired for too long if enabled...
         if ($this->claimTTL > 0) {
             $claimCutoff = $dbw->timestamp($now - $this->claimTTL);
             // Get the IDs of jobs that have be claimed but not finished after too long.
             // These jobs can be recycled into the queue by expiring the claim. Selecting
             // the IDs first means that the UPDATE can be done by primary key (less deadlocks).
             $res = $dbw->select('job', 'job_id', array('job_cmd' => $this->type, "job_token != {$dbw->addQuotes('')}", "job_token_timestamp < {$dbw->addQuotes($claimCutoff)}", "job_attempts < {$dbw->addQuotes($this->maxTries)}"), __METHOD__);
             $ids = array_map(function ($o) {
                 return $o->job_id;
             }, iterator_to_array($res));
             if (count($ids)) {
                 // Reset job_token for these jobs so that other runners will pick them up.
                 // Set the timestamp to the current time, as it is useful to now that the job
                 // was already tried before (the timestamp becomes the "released" time).
                 $dbw->update('job', array('job_token' => '', 'job_token_timestamp' => $dbw->timestamp($now)), array('job_id' => $ids), __METHOD__);
                 $affected = $dbw->affectedRows();
                 $count += $affected;
                 JobQueue::incrStats('job-recycle', $this->type, $affected, $this->wiki);
                 // The tasks recycled jobs or release delayed jobs into the queue
                 $this->cache->set($this->getCacheKey('empty'), 'false', self::CACHE_TTL_LONG);
                 $this->aggr->notifyQueueNonEmpty($this->wiki, $this->type);
             }
         }
         // Just destroy any stale jobs...
         $pruneCutoff = $dbw->timestamp($now - self::MAX_AGE_PRUNE);
         $conds = array('job_cmd' => $this->type, "job_token != {$dbw->addQuotes('')}", "job_token_timestamp < {$dbw->addQuotes($pruneCutoff)}");
         if ($this->claimTTL > 0) {
             // only prune jobs attempted too many times...
             $conds[] = "job_attempts >= {$dbw->addQuotes($this->maxTries)}";
         }
         // Get the IDs of jobs that are considered stale and should be removed. Selecting
         // the IDs first means that the UPDATE can be done by primary key (less deadlocks).
         $res = $dbw->select('job', 'job_id', $conds, __METHOD__);
         $ids = array_map(function ($o) {
             return $o->job_id;
         }, iterator_to_array($res));
         if (count($ids)) {
             $dbw->delete('job', array('job_id' => $ids), __METHOD__);
             $affected = $dbw->affectedRows();
             $count += $affected;
             JobQueue::incrStats('job-abandon', $this->type, $affected, $this->wiki);
         }
         $dbw->unlock("jobqueue-recycle-{$this->type}", __METHOD__);
     } catch (DBError $e) {
         $this->throwDBException($e);
     }
     return $count;
 }
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:64,代码来源:JobQueueDB.php

示例7: claimRandom

 /**
  * Reserve a row with a single UPDATE without holding row locks over RTTs...
  *
  * @param string $uuid 32 char hex string
  * @param int $rand Random unsigned integer (31 bits)
  * @param bool $gte Search for job_random >= $random (otherwise job_random <= $random)
  * @return stdClass|bool Row|false
  */
 protected function claimRandom($uuid, $rand, $gte)
 {
     $dbw = $this->getMasterDB();
     // Check cache to see if the queue has <= OFFSET items
     $tinyQueue = $this->cache->get($this->getCacheKey('small'));
     $row = false;
     // the row acquired
     $invertedDirection = false;
     // whether one job_random direction was already scanned
     // This uses a replication safe method for acquiring jobs. One could use UPDATE+LIMIT
     // instead, but that either uses ORDER BY (in which case it deadlocks in MySQL) or is
     // not replication safe. Due to http://bugs.mysql.com/bug.php?id=6980, subqueries cannot
     // be used here with MySQL.
     do {
         if ($tinyQueue) {
             // queue has <= MAX_OFFSET rows
             // For small queues, using OFFSET will overshoot and return no rows more often.
             // Instead, this uses job_random to pick a row (possibly checking both directions).
             $ineq = $gte ? '>=' : '<=';
             $dir = $gte ? 'ASC' : 'DESC';
             $row = $dbw->selectRow('job', self::selectFields(), array('job_cmd' => $this->type, 'job_token' => '', "job_random {$ineq} {$dbw->addQuotes($rand)}"), __METHOD__, array('ORDER BY' => "job_random {$dir}"));
             if (!$row && !$invertedDirection) {
                 $gte = !$gte;
                 $invertedDirection = true;
                 continue;
                 // try the other direction
             }
         } else {
             // table *may* have >= MAX_OFFSET rows
             // Bug 42614: "ORDER BY job_random" with a job_random inequality causes high CPU
             // in MySQL if there are many rows for some reason. This uses a small OFFSET
             // instead of job_random for reducing excess claim retries.
             $row = $dbw->selectRow('job', self::selectFields(), array('job_cmd' => $this->type, 'job_token' => ''), __METHOD__, array('OFFSET' => mt_rand(0, self::MAX_OFFSET)));
             if (!$row) {
                 $tinyQueue = true;
                 // we know the queue must have <= MAX_OFFSET rows
                 $this->cache->set($this->getCacheKey('small'), 1, 30);
                 continue;
                 // use job_random
             }
         }
         if ($row) {
             // claim the job
             $dbw->update('job', array('job_token' => $uuid, 'job_token_timestamp' => $dbw->timestamp(), 'job_attempts = job_attempts+1'), array('job_cmd' => $this->type, 'job_id' => $row->job_id, 'job_token' => ''), __METHOD__);
             // This might get raced out by another runner when claiming the previously
             // selected row. The use of job_random should minimize this problem, however.
             if (!$dbw->affectedRows()) {
                 $row = false;
                 // raced out
             }
         } else {
             break;
             // nothing to do
         }
     } while (!$row);
     return $row;
 }
开发者ID:jpena88,项目名称:mediawiki-dokku-deploy,代码行数:65,代码来源:JobQueueDB.php

示例8: deleteFileCache

	/**
	 * Delete the cached stat info for a file path.
	 * The cache key is salted for a while to prevent race conditions.
	 * Since negatives (404s) are not cached, this does not need to be called when
	 * a file is created at a path were there was none before.
	 *
	 * @param string $path Storage path
	 * @return void
	 */
	final protected function deleteFileCache( $path ) {
		$path = FileBackend::normalizeStoragePath( $path );
		if ( $path === null ) {
			return; // invalid storage path
		}
		if ( !$this->memCache->set( $this->fileCacheKey( $path ), 'PURGED', 300 ) ) {
			trigger_error( "Unable to delete stat cache for file $path." );
		}
	}
开发者ID:nahoj,项目名称:mediawiki_ynh,代码行数:18,代码来源:FileBackendStore.php

示例9: getFileContentsHashInternal

 /**
  * Get a hash of a file's contents, either by retrieving a previously-
  * computed hash from the cache, or by computing a hash from the file.
  *
  * @private
  * @param string $filePath Full path to the file.
  * @param string $algo Name of selected hashing algorithm.
  * @return string|bool Hash of file contents, or false if the file could not be read.
  */
 public function getFileContentsHashInternal($filePath, $algo = 'md4')
 {
     $mtime = MediaWiki\quietCall('filemtime', $filePath);
     if ($mtime === false) {
         return false;
     }
     $cacheKey = wfGlobalCacheKey(__CLASS__, $filePath, $mtime, $algo);
     $hash = $this->cache->get($cacheKey);
     if ($hash) {
         return $hash;
     }
     $contents = MediaWiki\quietCall('file_get_contents', $filePath);
     if ($contents === false) {
         return false;
     }
     $hash = hash($algo, $contents);
     $this->cache->set($cacheKey, $hash, 60 * 60 * 24);
     // 24h
     return $hash;
 }
开发者ID:jongfeli,项目名称:mediawiki,代码行数:29,代码来源:FileContentsHasher.php

示例10: getSites

 /**
  * @see SiteStore::getSites
  *
  * @since 1.25
  *
  * @return SiteList
  */
 public function getSites()
 {
     if ($this->sites === null) {
         $this->sites = $this->cache->get($this->getCacheKey());
         if (!is_object($this->sites)) {
             $this->sites = $this->siteStore->getSites();
             $this->cache->set($this->getCacheKey(), $this->sites, $this->cacheTimeout);
         }
     }
     return $this->sites;
 }
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:18,代码来源:CachingSiteStore.php

示例11: getFileContentsHashInternal

 /**
  * Get a hash of a file's contents, either by retrieving a previously-
  * computed hash from the cache, or by computing a hash from the file.
  *
  * @private
  * @param string $filePath Full path to the file.
  * @param string $algo Name of selected hashing algorithm.
  * @return string|bool Hash of file contents, or false if the file could not be read.
  */
 public function getFileContentsHashInternal($filePath, $algo = 'md4')
 {
     $mtime = filemtime($filePath);
     if ($mtime === false) {
         return false;
     }
     $cacheKey = $this->cache->makeGlobalKey(__CLASS__, $filePath, $mtime, $algo);
     $hash = $this->cache->get($cacheKey);
     if ($hash) {
         return $hash;
     }
     $contents = file_get_contents($filePath);
     if ($contents === false) {
         return false;
     }
     $hash = hash($algo, $contents);
     $this->cache->set($cacheKey, $hash, 60 * 60 * 24);
     // 24h
     return $hash;
 }
开发者ID:Acidburn0zzz,项目名称:mediawiki,代码行数:29,代码来源:FileContentsHasher.php

示例12: saveToCaches

 /**
  * Shortcut to update caches.
  *
  * @param array $cache Cached messages with a version.
  * @param string $dest Either "local-only" to save to local caches only
  *   or "all" to save to all caches.
  * @param string|bool $code Language code (default: false)
  * @return bool
  */
 protected function saveToCaches(array $cache, $dest, $code = false)
 {
     if ($dest === 'all') {
         $cacheKey = wfMemcKey('messages', $code);
         $success = $this->mMemc->set($cacheKey, $cache);
     } else {
         $success = true;
     }
     $this->setValidationHash($code, $cache);
     $this->saveToLocalCache($code, $cache);
     return $success;
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:21,代码来源:MessageCache.php

示例13: doWait

 /**
  * Wait for a given slave to catch up to the master pos stored in $this
  * @param int $index Server index
  * @param bool $open Check the server even if a new connection has to be made
  * @param int $timeout Max seconds to wait; default is mWaitTimeout
  * @return bool
  */
 protected function doWait($index, $open = false, $timeout = null)
 {
     $close = false;
     // close the connection afterwards
     // Check if we already know that the DB has reached this point
     $server = $this->getServerName($index);
     $key = $this->srvCache->makeGlobalKey(__CLASS__, 'last-known-pos', $server);
     /** @var DBMasterPos $knownReachedPos */
     $knownReachedPos = $this->srvCache->get($key);
     if ($knownReachedPos && $knownReachedPos->hasReached($this->mWaitForPos)) {
         wfDebugLog('replication', __METHOD__ . ": slave {$server} known to be caught up (pos >= {$knownReachedPos}).\n");
         return true;
     }
     // Find a connection to wait on, creating one if needed and allowed
     $conn = $this->getAnyOpenConnection($index);
     if (!$conn) {
         if (!$open) {
             wfDebugLog('replication', __METHOD__ . ": no connection open for {$server}\n");
             return false;
         } else {
             $conn = $this->openConnection($index, '');
             if (!$conn) {
                 wfDebugLog('replication', __METHOD__ . ": failed to connect to {$server}\n");
                 return false;
             }
             // Avoid connection spam in waitForAll() when connections
             // are made just for the sake of doing this lag check.
             $close = true;
         }
     }
     wfDebugLog('replication', __METHOD__ . ": Waiting for slave {$server} to catch up...\n");
     $timeout = $timeout ?: $this->mWaitTimeout;
     $result = $conn->masterPosWait($this->mWaitForPos, $timeout);
     if ($result == -1 || is_null($result)) {
         // Timed out waiting for slave, use master instead
         $msg = __METHOD__ . ": Timed out waiting on {$server} pos {$this->mWaitForPos}";
         wfDebugLog('replication', "{$msg}\n");
         wfDebugLog('DBPerformance', "{$msg}:\n" . wfBacktrace(true));
         $ok = false;
     } else {
         wfDebugLog('replication', __METHOD__ . ": Done\n");
         $ok = true;
         // Remember that the DB reached this point
         $this->srvCache->set($key, $this->mWaitForPos, BagOStuff::TTL_DAY);
     }
     if ($close) {
         $this->closeConnection($conn);
     }
     return $ok;
 }
开发者ID:admonkey,项目名称:mediawiki,代码行数:57,代码来源:LoadBalancer.php

示例14: getAuthentication

 /**
  * @return array|null Credential map
  */
 protected function getAuthentication()
 {
     if ($this->authErrorTimestamp !== null) {
         if (time() - $this->authErrorTimestamp < 60) {
             return null;
             // failed last attempt; don't bother
         } else {
             // actually retry this time
             $this->authErrorTimestamp = null;
         }
     }
     // Session keys expire after a while, so we renew them periodically
     $reAuth = time() - $this->authSessionTimestamp > $this->authTTL;
     // Authenticate with proxy and get a session key...
     if (!$this->authCreds || $reAuth) {
         $this->authSessionTimestamp = 0;
         $cacheKey = $this->getCredsCacheKey($this->swiftUser);
         $creds = $this->srvCache->get($cacheKey);
         // credentials
         // Try to use the credential cache
         if (isset($creds['auth_token']) && isset($creds['storage_url'])) {
             $this->authCreds = $creds;
             // Skew the timestamp for worst case to avoid using stale credentials
             $this->authSessionTimestamp = time() - ceil($this->authTTL / 2);
         } else {
             // cache miss
             list($rcode, $rdesc, $rhdrs, $rbody, $rerr) = $this->http->run(array('method' => 'GET', 'url' => "{$this->swiftAuthUrl}/v1.0", 'headers' => array('x-auth-user' => $this->swiftUser, 'x-auth-key' => $this->swiftKey)));
             if ($rcode >= 200 && $rcode <= 299) {
                 // OK
                 $this->authCreds = array('auth_token' => $rhdrs['x-auth-token'], 'storage_url' => $rhdrs['x-storage-url']);
                 $this->srvCache->set($cacheKey, $this->authCreds, ceil($this->authTTL / 2));
                 $this->authSessionTimestamp = time();
             } elseif ($rcode === 401) {
                 $this->onError(null, __METHOD__, array(), "Authentication failed.", $rcode);
                 $this->authErrorTimestamp = time();
                 return null;
             } else {
                 $this->onError(null, __METHOD__, array(), "HTTP return code: {$rcode}", $rcode);
                 $this->authErrorTimestamp = time();
                 return null;
             }
         }
         // Ceph RGW does not use <account> in URLs (OpenStack Swift uses "/v1/<account>")
         if (substr($this->authCreds['storage_url'], -3) === '/v1') {
             $this->isRGW = true;
             // take advantage of strong consistency in Ceph
         }
     }
     return $this->authCreds;
 }
开发者ID:OrBin,项目名称:mediawiki,代码行数:53,代码来源:SwiftFileBackend.php

示例15: getNotificationCount

 /**
  * Retrieves number of unread notifications that a user has, would return
  * $wgEchoMaxNotificationCount + 1 at most
  *
  * @param $cached bool Set to false to bypass the cache.
  * @param $dbSource int use master or slave database to pull count
  * @return integer: Number of unread notifications.
  */
 public function getNotificationCount($cached = true, $dbSource = DB_SLAVE)
 {
     global $wgEchoConfig;
     //XXCHANGEDXX - allow anons [sc|rs]
     // if ( $this->mUser->isAnon() ) {
     // return 0;
     // }
     $memcKey = wfMemcKey('echo-notification-count', $this->mUser->getId(), $wgEchoConfig['version']);
     if ($cached && $this->cache->get($memcKey) !== false) {
         return (int) $this->cache->get($memcKey);
     }
     $count = $this->storage->getNotificationCount($this->mUser, $dbSource);
     $this->cache->set($memcKey, $count, 86400);
     return (int) $count;
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:23,代码来源:NotifUser.php


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