[TASK][WIP] Move non class code back to source files
[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 * Cache clearing helper functions
26 *
27 * @package Extbase
28 * @subpackage Service
29 */
30 class Tx_Extbase_Service_CacheService implements t3lib_Singleton {
31
32 /**
33 * Clears the page cache
34 *
35 * @param mixed $pageIdsToClear (int) single or (array) multiple pageIds to clear the cache for
36 * @return void
37 */
38 public function clearPageCache($pageIdsToClear = NULL) {
39 if ($pageIdsToClear !== NULL && !is_array($pageIdsToClear)) {
40 $pageIdsToClear = array(intval($pageIdsToClear));
41 }
42 $this->flushPageCache($pageIdsToClear);
43 $this->flushPageSectionCache($pageIdsToClear);
44 }
45
46 /**
47 * Flushes cache_pages or cachingframework_cache_pages.
48 *
49 * @param array|NULL $pageIds pageIds to clear the cache for
50 * @return void
51 */
52 protected function flushPageCache($pageIds = NULL) {
53 $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
54 if ($pageIds !== NULL) {
55 foreach ($pageIds as $pageId) {
56 $pageCache->flushByTag('pageId_' . $pageId);
57 }
58 } else {
59 $pageCache->flush();
60 }
61 }
62
63 /**
64 * Flushes cache_pagesection or cachingframework_cache_pagesection.
65 *
66 * @param array|NULL $pageIds pageIds to clear the cache for
67 * @return void
68 */
69 protected function flushPageSectionCache($pageIds = NULL) {
70 $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
71 if ($pageIds !== NULL) {
72 foreach ($pageIds as $pageId) {
73 $pageSectionCache->flushByTag('pageId_' . $pageId);
74 }
75 } else {
76 $pageSectionCache->flush();
77 }
78 }
79
80 }
81
82 ?>