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