/** * Queries missing revisions. * * @return void * @throws \LogicException When no plugins are registered. */ public function refresh() { if (!$this->_plugins) { throw new \LogicException('Please register at least one revision log plugin.'); } $project_url = $this->_repositoryConnector->getProjectUrl($this->_repositoryUrl); // Initialize plugins with data from cache. $cache_key = 'log:' . $project_url; $cache = $this->_cacheManager->getCache($cache_key, $this->_getCacheInvalidator()); if (is_array($cache)) { foreach ($this->_plugins as $plugin_name => $plugin) { $plugin->setCollectedData($cache[$plugin_name]); } } $from_revision = $this->_getLastRevision(); $to_revision = $this->_repositoryConnector->getLastRevision($project_url); if ($to_revision > $from_revision) { $this->_queryRevisionData($from_revision, $to_revision); // Collect and cache plugin data. $cache = array(); foreach ($this->_plugins as $plugin_name => $plugin) { $cache[$plugin_name] = $plugin->getCollectedData(); } $this->_cacheManager->setCache($cache_key, $cache, $this->_getCacheInvalidator()); } }
/** * Runs the command. * * @param callable|null $callback Callback. * * @return string|\SimpleXMLElement */ public function run($callback = null) { $cache_key = $this->_getCacheKey(); if ($cache_key) { $output = $this->_cacheManager->getCache($cache_key, $this->_cacheInvalidator, $this->_cacheDuration); if (isset($output) && is_callable($callback)) { call_user_func($callback, Process::OUT, $output); } } if (!isset($output)) { $output = $this->_doRun($callback); if ($cache_key) { $this->_cacheManager->setCache($cache_key, $output, $this->_cacheInvalidator, $this->_cacheDuration); } } if (strpos($this->_commandLine, '--xml') !== false) { return simplexml_load_string($output); } return $output; }
public function testSetWithInvalidatorFailure() { $this->cacheManager->setCache('namespace:name', 'value', 'invalidator1'); $this->assertNull($this->cacheManager->getCache('namespace:name', 'invalidator2')); $this->assertCount(0, $this->getCacheFilenames('namespace')); }
public function testVerboseCacheHit() { $io = $this->prophesize('ConsoleHelpers\\ConsoleKit\\ConsoleIO'); $io->isVerbose()->willReturn(true)->shouldBeCalled(); // For "setCache" call. $this->expectVerboseOutput($io, '#^<debug>\\[cache\\]: .*/\\.svn-buddy/namespace_.*\\.cache \\(miss\\)</debug>$#'); // For "getCache" call. $this->expectVerboseOutput($io, '#^<debug>\\[cache\\]: .*/\\.svn-buddy/namespace_.*\\.cache \\(hit: .*\\)</debug>$#'); $cache_manager = new CacheManager($this->getWorkingDirectory(), $this->sizeHelper->reveal(), $io->reveal()); $cache_manager->setCache('namespace:name', 'OK'); $this->assertEquals('OK', $cache_manager->getCache('namespace:name')); }