*/
class Tx_Extbase_Service_CacheService implements t3lib_Singleton {
- /**
- * This is a wrapper for the global constant "TYPO3_UseCachingFramework" to make this class testable
- * @var boolean
- */
- protected $useCachingFramework = TYPO3_UseCachingFramework;
-
/**
* Clears the page cache
*
* @return void
*/
protected function flushPageCache($pageIds = NULL) {
- if ($this->useCachingFramework) {
- $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
+ $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
- if ($pageIds !== NULL) {
- foreach ($pageIds as $pageId) {
- $pageCache->flushByTag('pageId_' . $pageId);
- }
- } else {
- $pageCache->flush();
+ if ($pageIds !== NULL) {
+ foreach ($pageIds as $pageId) {
+ $pageCache->flushByTag('pageId_' . $pageId);
}
- } elseif ($pageIds !== NULL) {
- $GLOBALS['TYPO3_DB']->exec_DELETEquery(
- 'cache_pages',
- 'page_id IN (' . implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($pageIds)) . ')'
- );
} else {
- $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_pages');
+ $pageCache->flush();
}
}
* @return void
*/
protected function flushPageSectionCache($pageIds = NULL) {
- if ($this->useCachingFramework) {
- $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
+ $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
- if ($pageIds !== NULL) {
- foreach ($pageIds as $pageId) {
- $pageSectionCache->flushByTag('pageId_' . $pageId);
- }
- } else {
- $pageSectionCache->flush();
+ if ($pageIds !== NULL) {
+ foreach ($pageIds as $pageId) {
+ $pageSectionCache->flushByTag('pageId_' . $pageId);
}
- } elseif ($pageIds !== NULL) {
- $GLOBALS['TYPO3_DB']->exec_DELETEquery(
- 'cache_pagesection',
- 'page_id IN (' . implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($pageIds)) . ')'
- );
} else {
- $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_pagesection');
+ $pageSectionCache->flush();
}
}
}
/**
* @test
*/
- public function flushPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPagesIfCachingFrameworkIsEnabled() {
+ public function flushPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPages() {
$mockCacheFrontend = $this->getMock('t3lib_cache_frontend_Frontend');
$mockCacheFrontend->expects($this->at(0))->method('flushByTag')->with('pageId_1');
$mockCacheFrontend->expects($this->at(1))->method('flushByTag')->with('pageId_2');
$GLOBALS['typo3CacheManager']->expects($this->once())->method('getCache')->with('cache_pages')->will($this->returnValue($mockCacheFrontend));
- $this->cacheService->_set('useCachingFramework', TRUE);
$this->cacheService->_call('flushPageCache', array(1,2,3));
}
/**
* @test
*/
- public function flushPageCacheUsesCacheManagerToFlushCacheOfAllPagesIfCachingFrameworkIsEnabledAndPageIdsIsNull() {
+ public function flushPageCacheUsesCacheManagerToFlushCacheOfAllPagesIfPageIdsIsNull() {
$mockCacheFrontend = $this->getMock('t3lib_cache_frontend_Frontend');
$mockCacheFrontend->expects($this->once())->method('flush');
$GLOBALS['typo3CacheManager']->expects($this->once())->method('getCache')->with('cache_pages')->will($this->returnValue($mockCacheFrontend));
- $this->cacheService->_set('useCachingFramework', TRUE);
$this->cacheService->_call('flushPageCache');
}
/**
* @test
*/
- public function flushPageCacheFlushesCacheOfSpecifiedPagesDirectlyIfCachingFrameworkIsDisabled() {
- $GLOBALS['TYPO3_DB']->expects($this->once())->method('cleanIntArray')->with(array(1,2,3))->will($this->returnValue(array(3,2,1)));
- $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_DELETEquery')->with(
- 'cache_pages',
- 'page_id IN (3,2,1)'
- );
-
- $this->cacheService->_set('useCachingFramework', FALSE);
- $this->cacheService->_call('flushPageCache', array(1,2,3));
- }
-
- /**
- * test
- */
- public function flushPageCacheFlushesCacheOfAllPagesDirectlyIfCachingFrameworkIsDisabled() {
- $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_TRUNCATEquery')->with('cache_pages');
-
- $this->cacheService->_set('useCachingFramework', FALSE);
- $this->cacheService->_call('flushPageCache');
- }
-
- /**
- * @test
- */
- public function flushPageSectionCacheUsesCacheManagerToFlushCacheOfSpecifiedPageSectionsIfCachingFrameworkIsEnabled() {
+ public function flushPageSectionCacheUsesCacheManagerToFlushCacheOfSpecifiedPageSections() {
$mockCacheFrontend = $this->getMock('t3lib_cache_frontend_Frontend');
$mockCacheFrontend->expects($this->at(0))->method('flushByTag')->with('pageId_1');
$mockCacheFrontend->expects($this->at(1))->method('flushByTag')->with('pageId_2');
$GLOBALS['typo3CacheManager']->expects($this->once())->method('getCache')->with('cache_pagesection')->will($this->returnValue($mockCacheFrontend));
- $this->cacheService->_set('useCachingFramework', TRUE);
$this->cacheService->_call('flushPageSectionCache', array(1,2,3));
}
/**
* @test
*/
- public function flushPageSectionCacheUsesCacheManagerToFlushCacheOfAllPageSectionsIfCachingFrameworkIsEnabledAndPageIdsIsNull() {
+ public function flushPageSectionCacheUsesCacheManagerToFlushCacheOfAllPageSectionsIfPageIdsIsNull() {
$mockCacheFrontend = $this->getMock('t3lib_cache_frontend_Frontend');
$mockCacheFrontend->expects($this->once())->method('flush');
$GLOBALS['typo3CacheManager']->expects($this->once())->method('getCache')->with('cache_pagesection')->will($this->returnValue($mockCacheFrontend));
- $this->cacheService->_set('useCachingFramework', TRUE);
- $this->cacheService->_call('flushPageSectionCache');
- }
-
- /**
- * @test
- */
- public function flushPageSectionCacheFlushesCacheOfSpecifiedPageSectionsDirectlyIfCachingFrameworkIsDisabled() {
- $GLOBALS['TYPO3_DB']->expects($this->once())->method('cleanIntArray')->with(array(1,2,3))->will($this->returnValue(array(3,2,1)));
- $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_DELETEquery')->with(
- 'cache_pagesection',
- 'page_id IN (3,2,1)'
- );
-
- $this->cacheService->_set('useCachingFramework', FALSE);
- $this->cacheService->_call('flushPageSectionCache', array(1,2,3));
- }
-
- /**
- * test
- */
- public function flushPageSectionCacheCacheFlushesCacheOfAllPageSectionsDirectlyIfCachingFrameworkIsDisabled() {
- $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_TRUNCATEquery')->with('cache_pagesection');
-
- $this->cacheService->_set('useCachingFramework', FALSE);
$this->cacheService->_call('flushPageSectionCache');
}