Esempio n. 1
0
 /**
  * Clear RepoGroup process cache used for finding a file
  * @param Title|null $title Title of the file or null to clear all files
  */
 public function clearCache(Title $title = null)
 {
     if ($title == null) {
         $this->cache->clear();
     } else {
         $this->cache->clear($title->getDBkey());
     }
 }
 /**
  * Create a new BacklinkCache or reuse any existing one.
  * Currently, only one cache instance can exist; callers that
  * need multiple backlink cache objects should keep them in scope.
  *
  * @param Title $title : Title object to get a backlink cache for
  * @return BacklinkCache
  */
 public static function get(Title $title)
 {
     if (!self::$cache) {
         // init cache
         self::$cache = new ProcessCacheLRU(1);
     }
     $dbKey = $title->getPrefixedDBkey();
     if (!self::$cache->has($dbKey, 'obj')) {
         self::$cache->set($dbKey, 'obj', new self($title));
     }
     return self::$cache->get($dbKey, 'obj');
 }
Esempio n. 3
0
	protected function doPrimeContainerCache( array $containerInfo ) {
		try {
			$conn = $this->getConnection(); // Swift proxy connection
			foreach ( $containerInfo as $container => $info ) {
				$contObj = new CF_Container( $conn->cfs_auth, $conn->cfs_http,
					$container, $info['count'], $info['bytes'] );
				$this->connContainerCache->set( $container, 'obj', $contObj );
			}
		} catch ( CloudFilesException $e ) { // some other exception?
			$this->handleException( $e, null, __METHOD__, array() );
		}
	}
Esempio n. 4
0
	/**
	 * Check if jobs should not be popped of a queue right now.
	 * This is only used for performance, such as to avoid spamming
	 * the queue with many sub-jobs before they actually get run.
	 *
	 * @param $type string
	 * @return bool
	 */
	public function isQueueDeprioritized( $type ) {
		if ( $this->cache->has( 'isDeprioritized', $type, 5 ) ) {
			return $this->cache->get( 'isDeprioritized', $type );
		}
		if ( $type === 'refreshLinks2' ) {
			// Don't keep converting refreshLinks2 => refreshLinks jobs if the
			// later jobs have not been done yet. This helps throttle queue spam.
			$deprioritized = !$this->get( 'refreshLinks' )->isEmpty();
			$this->cache->set( 'isDeprioritized', $type, $deprioritized );
			return $deprioritized;
		}
		return false;
	}
 /**
  * Translate legacy "title" paths to their "sha1" counterparts
  *
  * E.g. mwstore://local-backend/local-public/a/ab/<name>.jpg
  * => mwstore://local-backend/local-original/x/y/z/<sha1>.jpg
  *
  * @param array $paths
  * @param bool $latest
  * @return array Translated paths in same order
  */
 public function getBackendPaths(array $paths, $latest = true)
 {
     $db = $this->getDB($latest ? DB_MASTER : DB_SLAVE);
     $origBasePath = $this->backend->getContainerStoragePath("{$this->repoName}-original");
     // @TODO: batching
     $resolved = array();
     foreach ($paths as $i => $path) {
         if (!$latest && $this->resolvedPathCache->has($path, 'target', 10)) {
             $resolved[$i] = $this->resolvedPathCache->get($path, 'target');
             continue;
         }
         list(, $container, $rel) = FileBackend::splitStoragePath($path);
         if ($container === "{$this->repoName}-public") {
             $name = basename($path);
             if (strpos($path, '!') !== false) {
                 $sha1 = $db->selectField('oldimage', 'oi_sha1', array('oi_archive_name' => $name), __METHOD__);
             } else {
                 $sha1 = $db->selectField('image', 'img_sha1', array('img_name' => $name), __METHOD__);
             }
             if (!strlen($sha1)) {
                 $resolved[$i] = $path;
                 // give up
                 continue;
             }
             $resolved[$i] = $this->getPathForSHA1($sha1);
             $this->resolvedPathCache->set($path, 'target', $resolved[$i]);
         } elseif ($container === "{$this->repoName}-deleted") {
             $name = basename($path);
             // <hash>.<ext>
             $sha1 = substr($name, 0, strpos($name, '.'));
             // ignore extension
             $resolved[$i] = $this->getPathForSHA1($sha1);
             $this->resolvedPathCache->set($path, 'target', $resolved[$i]);
         } else {
             $resolved[$i] = $path;
         }
     }
     $res = array();
     foreach ($paths as $i => $path) {
         $res[$i] = $resolved[$i];
     }
     return $res;
 }
Esempio n. 6
0
 /**
  * Pop a job off one of the job queues
  *
  * This pops a job off a queue as specified by $wgJobTypeConf and
  * updates the aggregate job queue information cache as needed.
  *
  * @param int|string $qtype JobQueueGroup::TYPE_* constant or job type string
  * @param int $flags Bitfield of JobQueueGroup::USE_* constants
  * @param array $blacklist List of job types to ignore
  * @return Job|bool Returns false on failure
  */
 public function pop($qtype = self::TYPE_DEFAULT, $flags = 0, array $blacklist = array())
 {
     $job = false;
     if (is_string($qtype)) {
         // specific job type
         if (!in_array($qtype, $blacklist)) {
             $job = $this->get($qtype)->pop();
             if (!$job) {
                 JobQueueAggregator::singleton()->notifyQueueEmpty($this->wiki, $qtype);
             }
         }
     } else {
         // any job in the "default" jobs types
         if ($flags & self::USE_CACHE) {
             if (!$this->cache->has('queues-ready', 'list', self::PROC_CACHE_TTL)) {
                 $this->cache->set('queues-ready', 'list', $this->getQueuesWithJobs());
             }
             $types = $this->cache->get('queues-ready', 'list');
         } else {
             $types = $this->getQueuesWithJobs();
         }
         if ($qtype == self::TYPE_DEFAULT) {
             $types = array_intersect($types, $this->getDefaultQueueTypes());
         }
         $types = array_diff($types, $blacklist);
         // avoid selected types
         shuffle($types);
         // avoid starvation
         foreach ($types as $type) {
             // for each queue...
             $job = $this->get($type)->pop();
             if ($job) {
                 // found
                 break;
             } else {
                 // not found
                 JobQueueAggregator::singleton()->notifyQueueEmpty($this->wiki, $type);
                 $this->cache->clear('queues-ready');
             }
         }
     }
     return $job;
 }
Esempio n. 7
0
 /**
  * Do a batch lookup from cache for file stats for all paths
  * used in a list of storage paths or FileOp objects.
  * This loads the persistent cache values into the process cache.
  *
  * @param array $items List of storage paths or FileOps
  * @return void
  */
 protected final function primeFileCache(array $items)
 {
     wfProfileIn(__METHOD__);
     wfProfileIn(__METHOD__ . '-' . $this->name);
     $paths = array();
     // list of storage paths
     $pathNames = array();
     // (cache key => storage path)
     // Get all the paths/containers from the items...
     foreach ($items as $item) {
         if ($item instanceof FileOp) {
             $paths = array_merge($paths, $item->storagePathsRead());
             $paths = array_merge($paths, $item->storagePathsChanged());
         } elseif (self::isStoragePath($item)) {
             $paths[] = FileBackend::normalizeStoragePath($item);
         }
     }
     // Get rid of any paths that failed normalization...
     $paths = array_filter($paths, 'strlen');
     // remove nulls
     // Get all the corresponding cache keys for paths...
     foreach ($paths as $path) {
         list(, $rel, ) = $this->resolveStoragePath($path);
         if ($rel !== null) {
             // valid path for this backend
             $pathNames[$this->fileCacheKey($path)] = $path;
         }
     }
     // Get all cache entries for these container cache keys...
     $values = $this->memCache->getMulti(array_keys($pathNames));
     foreach ($values as $cacheKey => $val) {
         if (is_array($val)) {
             $path = $pathNames[$cacheKey];
             $this->cheapCache->set($path, 'stat', $val);
             if (isset($val['sha1'])) {
                 // some backends store SHA-1 as metadata
                 $this->cheapCache->set($path, 'sha1', array('hash' => $val['sha1'], 'latest' => $val['latest']));
             }
         }
     }
     wfProfileOut(__METHOD__ . '-' . $this->name);
     wfProfileOut(__METHOD__);
 }
 /**
  * Clear the cache for slag lag delay times
  */
 public function clearLagTimeCache()
 {
     $this->mProcCache->clear('slave_lag');
 }