/** * @test */ public function flushCachesCallsTheFlushMethodOfAllRegisteredCaches() { $cache1 = $this->getMockBuilder('TYPO3\\Flow\\Cache\\Frontend\\AbstractFrontend')->disableOriginalConstructor()->getMock(); $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1')); $cache1->expects($this->once())->method('flush'); $this->cacheManager->registerCache($cache1); $cache2 = $this->getMockBuilder('TYPO3\\Flow\\Cache\\Frontend\\AbstractFrontend')->disableOriginalConstructor()->getMock(); $cache2->expects($this->once())->method('flush'); $this->cacheManager->registerCache($cache2); $this->cacheManager->flushCaches(); }
/** * Factory method which creates the specified cache along with the specified kind of backend. * After creating the cache, it will be registered at the cache manager. * * @param string $cacheIdentifier The name / identifier of the cache to create * @param string $cacheObjectName Object name of the cache frontend * @param string $backendObjectName Object name of the cache backend * @param array $backendOptions (optional) Array of backend options * @return \TYPO3\Flow\Cache\Frontend\FrontendInterface The created cache frontend * @throws \TYPO3\Flow\Cache\Exception\InvalidBackendException * @throws \TYPO3\Flow\Cache\Exception\InvalidCacheException * @api */ public function create($cacheIdentifier, $cacheObjectName, $backendObjectName, array $backendOptions = array()) { $backend = new $backendObjectName($this->context, $backendOptions); if (!$backend instanceof \TYPO3\Flow\Cache\Backend\BackendInterface) { throw new \TYPO3\Flow\Cache\Exception\InvalidBackendException('"' . $backendObjectName . '" is not a valid cache backend object.', 1216304301); } $backend->injectEnvironment($this->environment); if (is_callable(array($backend, 'initializeObject'))) { $backend->initializeObject(\TYPO3\Flow\Object\ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED); } $cache = new $cacheObjectName($cacheIdentifier, $backend); if (!$cache instanceof \TYPO3\Flow\Cache\Frontend\FrontendInterface) { throw new \TYPO3\Flow\Cache\Exception\InvalidCacheException('"' . $cacheObjectName . '" is not a valid cache frontend object.', 1216304300); } if (is_callable(array($cache, 'initializeObject'))) { $cache->initializeObject(\TYPO3\Flow\Object\ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED); } $this->cacheManager->registerCache($cache); return $cache; }
/** * Factory method which creates the specified cache along with the specified kind of backend. * After creating the cache, it will be registered at the cache manager. * * @param string $cacheIdentifier The name / identifier of the cache to create * @param string $cacheObjectName Object name of the cache frontend * @param string $backendObjectName Object name of the cache backend * @param array $backendOptions (optional) Array of backend options * @param boolean $persistent If the new cache should be marked as "persistent" * @return Frontend\FrontendInterface The created cache frontend * @throws Exception\InvalidBackendException * @throws Exception\InvalidCacheException * @api */ public function create($cacheIdentifier, $cacheObjectName, $backendObjectName, array $backendOptions = [], $persistent = false) { $backend = new $backendObjectName($this->context, $backendOptions); if (!$backend instanceof Backend\BackendInterface) { throw new Exception\InvalidBackendException('"' . $backendObjectName . '" is not a valid cache backend object.', 1216304301); } $backend->injectEnvironment($this->environment); if (is_callable([$backend, 'injectCacheManager'])) { $backend->injectCacheManager($this->cacheManager); } if (is_callable([$backend, 'initializeObject'])) { $backend->initializeObject(ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED); } $cache = new $cacheObjectName($cacheIdentifier, $backend); if (!$cache instanceof Frontend\FrontendInterface) { throw new Exception\InvalidCacheException('"' . $cacheObjectName . '" is not a valid cache frontend object.', 1216304300); } $this->cacheManager->registerCache($cache, $persistent); if (is_callable([$cache, 'initializeObject'])) { $cache->initializeObject(ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED); } return $cache; }