/** * @test */ public function createRegistersTheCacheAtTheCacheManager() { $cacheManager = new CacheManager(); $factory = new CacheFactory(new ApplicationContext('Testing'), $cacheManager, $this->mockEnvironment); $this->assertFalse($cacheManager->hasCache('TYPO3_Flow_Cache_FactoryTest_Cache')); $factory->create('TYPO3_Flow_Cache_FactoryTest_Cache', \TYPO3\Flow\Cache\Frontend\VariableFrontend::class, \TYPO3\Flow\Cache\Backend\FileBackend::class); $this->assertTrue($cacheManager->hasCache('TYPO3_Flow_Cache_FactoryTest_Cache')); $this->assertFalse($cacheManager->isCachePersistent('TYPO3_Flow_Cache_FactoryTest_Cache')); $this->assertFalse($cacheManager->hasCache('Persistent_Cache')); $factory->create('Persistent_Cache', \TYPO3\Flow\Cache\Frontend\VariableFrontend::class, \TYPO3\Flow\Cache\Backend\FileBackend::class, array(), true); $this->assertTrue($cacheManager->hasCache('Persistent_Cache')); $this->assertTrue($cacheManager->isCachePersistent('Persistent_Cache')); }
/** * @test */ public function hasCacheReturnsCorrectResult() { $cache1 = $this->getMockBuilder(\TYPO3\Flow\Cache\Frontend\AbstractFrontend::class)->disableOriginalConstructor()->getMock(); $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1')); $this->cacheManager->registerCache($cache1); $this->assertTrue($this->cacheManager->hasCache('cache1'), 'hasCache() did not return TRUE.'); $this->assertFalse($this->cacheManager->hasCache('cache2'), 'hasCache() did not return FALSE.'); }
/** * Flushes a particular cache by its identifier * * Given a cache identifier, this flushes just that one cache. To find * the cache identifiers, you can use the configuration:show command with * the type set to "Caches". * * Note that this does not have a force-flush option since it's not * meant to remove temporary code data, resulting into a broken state if * code files lack. * * @param string $identifier Cache identifier to flush cache for * @return void * @see typo3.flow:cache:flush * @see typo3.flow:configuration:show */ public function flushOneCommand($identifier) { if (!$this->cacheManager->hasCache($identifier)) { $this->outputLine('The cache "%s" does not exist.', array($identifier)); $cacheConfigurations = $this->cacheManager->getCacheConfigurations(); $shortestDistance = -1; foreach (array_keys($cacheConfigurations) as $existingIdentifier) { $distance = levenshtein($existingIdentifier, $identifier); if ($distance <= $shortestDistance || $shortestDistance < 0) { $shortestDistance = $distance; $closestIdentifier = $existingIdentifier; } } if (isset($closestIdentifier)) { $this->outputLine('Did you mean "%s"?', array($closestIdentifier)); } $this->quit(1); } $this->cacheManager->getCache($identifier)->flush(); $this->outputLine('Flushed "%s" cache for "%s" context.', array($identifier, $this->bootstrap->getContext())); $this->sendAndExit(0); }