*/
protected $reflectionService;
+ /**
+ * @var Tx_Extbase_Service_CacheService
+ */
+ protected $cacheService;
+
/**
* The current view, as resolved by resolveView()
*
protected $errorMethodName = 'errorAction';
/**
- * Injects the reflection service
- *
* @param Tx_Extbase_Reflection_Service $reflectionService
* @return void
*/
$this->reflectionService = $reflectionService;
}
+ /**
+ * @param Tx_Extbase_Service_CacheService $cacheService
+ * @return void
+ */
+ public function injectCacheService(Tx_Extbase_Service_CacheService $cacheService) {
+ $this->cacheService = $cacheService;
+ }
+
/**
* Checks if the current request type is supported by the controller.
*
if (isset($extbaseSettings['persistence']['enableAutomaticCacheClearing']) && $extbaseSettings['persistence']['enableAutomaticCacheClearing'] === '1') {
if (isset($GLOBALS['TSFE'])) {
$pageUid = $GLOBALS['TSFE']->id;
- Tx_Extbase_Utility_Cache::clearPageCache(array($pageUid));
+ $this->cacheService->clearPageCache(array($pageUid));
}
}
}
*/
protected $configurationManager;
+ /**
+ * @var Tx_Extbase_Service_CacheService
+ */
+ protected $cacheService;
+
/**
* Constructor. takes the database handle from $GLOBALS['TYPO3_DB']
*/
$this->dataMapper = $dataMapper;
}
+ /**
+ * @param Tx_Extbase_Service_CacheService $cacheService
+ * @return void
+ */
+ public function injectCacheService(Tx_Extbase_Service_CacheService $cacheService) {
+ $this->cacheService = $cacheService;
+ }
+
/**
* Adds a row to the storage
*
}
// TODO check if we can hand this over to the Dispatcher to clear the page only once, this will save around 10% time while inserting and updating
- Tx_Extbase_Utility_Cache::clearPageCache($pageIdsToClear);
+ $this->cacheService->clearPageCache($pageIdsToClear);
}
}
--- /dev/null
+<?php
+/***************************************************************
+* Copyright notice
+*
+* (c) 2011 Extbase Team
+* All rights reserved
+*
+* This script is part of the TYPO3 project. The TYPO3 project is
+* free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* The GNU General Public License can be found at
+* http://www.gnu.org/copyleft/gpl.html.
+*
+* This script is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Cache clearing helper functions
+ *
+ * @package Extbase
+ * @subpackage Service
+ */
+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
+ *
+ * @param mixed $pageIdsToClear (int) single or (array) multiple pageIds to clear the cache for
+ * @return void
+ */
+ public function clearPageCache($pageIdsToClear = NULL) {
+ if ($pageIdsToClear !== NULL && !is_array($pageIdsToClear)) {
+ $pageIdsToClear = array(intval($pageIdsToClear));
+ }
+
+ $this->flushPageCache($pageIdsToClear);
+ $this->flushPageSectionCache($pageIdsToClear);
+ }
+
+ /**
+ * Flushes cache_pages or cachingframework_cache_pages.
+ *
+ * @param array $pageIdsToClear pageIds to clear the cache for
+ * @return void
+ */
+ protected function flushPageCache($pageIds = NULL) {
+ if ($this->useCachingFramework) {
+ $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
+
+ if ($pageIds !== NULL) {
+ foreach ($pageIds as $pageId) {
+ $pageCache->flushByTag('pageId_' . $pageId);
+ }
+ } else {
+ $pageCache->flush();
+ }
+ } 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');
+ }
+ }
+
+ /**
+ * Flushes cache_pagesection or cachingframework_cache_pagesection.
+ *
+ * @param array $pageIdsToClear pageIds to clear the cache for
+ * @return void
+ */
+ protected function flushPageSectionCache($pageIds = NULL) {
+ if ($this->useCachingFramework) {
+ $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
+
+ if ($pageIds !== NULL) {
+ foreach ($pageIds as $pageId) {
+ $pageSectionCache->flushByTag('pageId_' . $pageId);
+ }
+ } else {
+ $pageSectionCache->flush();
+ }
+ } 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');
+ }
+ }
+}
+?>
\ No newline at end of file
*
* @package Extbase
* @subpackage Utility
- * @version $Id$
+ * @deprecated since Extbase 1.4.0; will be removed in Extbase 1.6.0. Please use Tx_Extbase_Service_CacheService instead
*/
class Tx_Extbase_Utility_Cache {
* @return void
*/
static public function clearPageCache($pageIdsToClear = NULL) {
- if ($pageIdsToClear !== NULL && !is_array($pageIdsToClear)) {
- $pageIdsToClear = array(intval($pageIdsToClear));
- }
-
- self::flushPageCache($pageIdsToClear);
- self::flushPageSectionCache($pageIdsToClear);
- }
-
- /**
- * Flushes cache_pages or cachinframework_cache_pages.
- *
- * @param array $pageIdsToClear pageIds to clear the cache for
- * @return void
- */
- static protected function flushPageCache($pageIds = NULL) {
- if (TYPO3_UseCachingFramework) {
- $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
-
- if ($pageIds !== NULL) {
- foreach ($pageIds as $pageId) {
- $pageCache->flushByTag('pageId_' . $pageId);
- }
- } else {
- $pageCache->flush();
- }
- } 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');
- }
- }
-
- /**
- * Flushes cache_pagesection or cachingframework_cache_pagesection.
- *
- * @param array $pageIdsToClear pageIds to clear the cache for
- * @return void
- */
- static protected function flushPageSectionCache($pageIds = NULL) {
- if (TYPO3_UseCachingFramework) {
- $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
-
- if ($pageIds !== NULL) {
- foreach ($pageIds as $pageId) {
- $pageSectionCache->flushByTag('pageId_' . $pageId);
- }
- } else {
- $pageSectionCache->flush();
- }
- } 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');
- }
+ t3lib_div::logDeprecatedFunction();
+ $objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
+ $cacheService = $objectManager->get('Tx_Extbase_Service_CacheService');
+ $cacheService->clearPageCache($pageIdsToClear);
}
}
?>
\ No newline at end of file
--- /dev/null
+<?php
+/***************************************************************
+* Copyright notice
+*
+* (c) 2011 Extbase Team
+* All rights reserved
+*
+* This script is part of the TYPO3 project. The TYPO3 project is
+* free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* The GNU General Public License can be found at
+* http://www.gnu.org/copyleft/gpl.html.
+*
+* This script is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+
+/**
+ * Testcase for class Tx_Extbase_Service_CacheService
+ *
+ * @package Extbase
+ * @subpackage extbase
+ */
+
+class Tx_Extbase_Tests_Unit_Service_CacheServiceTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+ /**
+ * @var Tx_Extbase_Service_CacheService
+ */
+ protected $cacheService;
+
+ /**
+ * @var t3lib_DB
+ */
+ protected $typo3DbBackup;
+
+ /**
+ * @var t3lib_cache_Manager
+ */
+ protected $cacheManagerBackup;
+
+ public function setUp() {
+ $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
+ $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB');
+
+ $this->cacheManagerBackup = $GLOBALS['typo3CacheManager'];
+ $GLOBALS['typo3CacheManager'] = $this->getMock('t3lib_cache_Manager');
+
+ $this->cacheService = $this->getAccessibleMock('Tx_Extbase_Service_CacheService', array('dummy'));
+ }
+
+ /**
+ * @test
+ */
+ public function clearPageCacheConvertsPageIdsToArray() {
+ $cacheService = $this->getMock('Tx_Extbase_Service_CacheService', array('flushPageCache', 'flushPageSectionCache'));
+ $cacheService->expects($this->once())->method('flushPageCache')->with(array(123));
+ $cacheService->expects($this->once())->method('flushPageSectionCache')->with(array(123));
+ $cacheService->clearPageCache(123);
+ }
+
+ /**
+ * @test
+ */
+ public function clearPageCacheConvertsPageIdsToNumericArray() {
+ $cacheService = $this->getMock('Tx_Extbase_Service_CacheService', array('flushPageCache', 'flushPageSectionCache'));
+ $cacheService->expects($this->once())->method('flushPageCache')->with(array(0));
+ $cacheService->expects($this->once())->method('flushPageSectionCache')->with(array(0));
+ $cacheService->clearPageCache('Foo');
+ }
+
+ /**
+ * @test
+ */
+ public function clearPageCacheDoesNotConvertPageIdsIfNoneAreSpecified() {
+ $cacheService = $this->getMock('Tx_Extbase_Service_CacheService', array('flushPageCache', 'flushPageSectionCache'));
+ $cacheService->expects($this->once())->method('flushPageCache')->with(NULL);
+ $cacheService->expects($this->once())->method('flushPageSectionCache')->with(NULL);
+ $cacheService->clearPageCache();
+ }
+
+ /**
+ * @test
+ */
+ public function flushPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPagesIfCachingFrameworkIsEnabled() {
+ $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');
+ $mockCacheFrontend->expects($this->at(2))->method('flushByTag')->with('pageId_3');
+
+ $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() {
+ $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() {
+ $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');
+ $mockCacheFrontend->expects($this->at(2))->method('flushByTag')->with('pageId_3');
+
+ $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() {
+ $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');
+ }
+
+}
+?>
\ No newline at end of file
* @subpackage extbase
*/
-class Tx_Extbase_Tests_Unit_Service_FlexFormServiceTest extends tx_phpunit_testcase {
+class Tx_Extbase_Tests_Unit_Service_FlexFormServiceTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
/**
* @var Tx_Extbase_Service_FlexFormService