Merge "[TASK] Remove trailing whitespace"
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Service / CacheService.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Extbase Team
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Cache clearing helper functions
27 *
28 * @package Extbase
29 * @subpackage Service
30 */
31 class Tx_Extbase_Service_CacheService implements t3lib_Singleton {
32
33 /**
34 * Clears the page cache
35 *
36 * @param mixed $pageIdsToClear (int) single or (array) multiple pageIds to clear the cache for
37 * @return void
38 */
39 public function clearPageCache($pageIdsToClear = NULL) {
40 if ($pageIdsToClear !== NULL && !is_array($pageIdsToClear)) {
41 $pageIdsToClear = array(intval($pageIdsToClear));
42 }
43
44 $this->flushPageCache($pageIdsToClear);
45 $this->flushPageSectionCache($pageIdsToClear);
46 }
47
48 /**
49 * Flushes cache_pages or cachingframework_cache_pages.
50 *
51 * @param array $pageIdsToClear pageIds to clear the cache for
52 * @return void
53 */
54 protected function flushPageCache($pageIds = NULL) {
55 $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
56
57 if ($pageIds !== NULL) {
58 foreach ($pageIds as $pageId) {
59 $pageCache->flushByTag('pageId_' . $pageId);
60 }
61 } else {
62 $pageCache->flush();
63 }
64 }
65
66 /**
67 * Flushes cache_pagesection or cachingframework_cache_pagesection.
68 *
69 * @param array $pageIdsToClear pageIds to clear the cache for
70 * @return void
71 */
72 protected function flushPageSectionCache($pageIds = NULL) {
73 $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
74
75 if ($pageIds !== NULL) {
76 foreach ($pageIds as $pageId) {
77 $pageSectionCache->flushByTag('pageId_' . $pageId);
78 }
79 } else {
80 $pageSectionCache->flush();
81 }
82 }
83 }
84 ?>