/** * @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')); }
/** * Sets a reference to the cache frontend which uses this backend and * initializes the default cache directory. * * @param \TYPO3\Flow\Cache\Frontend\FrontendInterface $cache The cache frontend * @return void * @throws Exception */ public function setCache(FrontendInterface $cache) { parent::setCache($cache); $cacheDirectory = $this->cacheDirectory; if ($cacheDirectory == '') { $codeOrData = $cache instanceof PhpFrontend ? 'Code' : 'Data'; $baseDirectory = $this->cacheManager->isCachePersistent($cache->getIdentifier()) ? FLOW_PATH_DATA . 'Persistent/' : $this->environment->getPathToTemporaryDirectory(); $cacheDirectory = $baseDirectory . 'Cache/' . $codeOrData . '/' . $this->cacheIdentifier . '/'; } if (!is_writable($cacheDirectory)) { try { \TYPO3\Flow\Utility\Files::createDirectoryRecursively($cacheDirectory); } catch (\TYPO3\Flow\Utility\Exception $exception) { throw new Exception('The cache directory "' . $cacheDirectory . '" could not be created.', 1264426237); } } if (!is_dir($cacheDirectory) && !is_link($cacheDirectory)) { throw new Exception('The cache directory "' . $cacheDirectory . '" does not exist.', 1203965199); } if (!is_writable($cacheDirectory)) { throw new Exception('The cache directory "' . $cacheDirectory . '" is not writable.', 1203965200); } $this->cacheDirectory = $cacheDirectory; $this->cacheEntryFileExtension = $cache instanceof PhpFrontend ? '.php' : ''; }
/** * Sets a reference to the cache frontend which uses this backend and * initializes the default cache directory. * * @param \TYPO3\Flow\Cache\Frontend\FrontendInterface $cache The cache frontend * @return void * @throws \TYPO3\Flow\Cache\Exception */ public function setCache(FrontendInterface $cache) { parent::setCache($cache); $cacheDirectory = $this->cacheDirectory; if ($cacheDirectory == '') { $codeOrData = $cache instanceof PhpFrontend ? 'Code' : 'Data'; $baseDirectory = $this->cacheManager->isCachePersistent($cache->getIdentifier()) ? FLOW_PATH_DATA . 'Persistent/' : $this->environment->getPathToTemporaryDirectory(); $cacheDirectory = $baseDirectory . 'Cache/' . $codeOrData . '/' . $this->cacheIdentifier . '/'; } if (!is_writable($cacheDirectory)) { try { \TYPO3\Flow\Utility\Files::createDirectoryRecursively($cacheDirectory); } catch (\TYPO3\Flow\Utility\Exception $exception) { throw new \TYPO3\Flow\Cache\Exception('The cache directory "' . $cacheDirectory . '" could not be created.', 1264426237); } } if (!is_dir($cacheDirectory) && !is_link($cacheDirectory)) { throw new \TYPO3\Flow\Cache\Exception('The cache directory "' . $cacheDirectory . '" does not exist.', 1203965199); } if (!is_writable($cacheDirectory)) { throw new \TYPO3\Flow\Cache\Exception('The cache directory "' . $cacheDirectory . '" is not writable.', 1203965200); } $this->cacheDirectory = $cacheDirectory; $this->cacheEntryFileExtension = $cache instanceof PhpFrontend ? '.php' : ''; if (strlen($this->cacheDirectory) + 23 > $this->environment->getMaximumPathLength()) { throw new \TYPO3\Flow\Cache\Exception('The length of the temporary cache path "' . $this->cacheDirectory . '" exceeds the maximum path length of ' . ($this->environment->getMaximumPathLength() - 23) . '. Please consider setting the temporaryDirectoryBase option to a shorter path. ', 1248710426); } }
/** * @test */ public function isCachePersistentReturnsCorrectResult() { $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); $cache2 = $this->getMockBuilder(\TYPO3\Flow\Cache\Frontend\AbstractFrontend::class)->disableOriginalConstructor()->getMock(); $cache2->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache2')); $this->cacheManager->registerCache($cache2, TRUE); $this->assertFalse($this->cacheManager->isCachePersistent('cache1')); $this->assertTrue($this->cacheManager->isCachePersistent('cache2')); }