TYPO3 CMS  TYPO3_7-6
CacheService.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
25  protected $pageIdStack;
26 
30  protected $cacheManager;
31 
35  public function injectCacheManager(\TYPO3\CMS\Core\Cache\CacheManager $cacheManager)
36  {
37  $this->cacheManager = $cacheManager;
38  }
39 
43  public function __construct()
44  {
45  $this->pageIdStack = new \SplStack;
46  }
47 
51  public function getPageIdStack()
52  {
53  return $this->pageIdStack;
54  }
55 
62  public function clearPageCache($pageIdsToClear = null)
63  {
64  if ($pageIdsToClear === null) {
65  $this->cacheManager->flushCachesInGroup('pages');
66  } else {
67  if (!is_array($pageIdsToClear)) {
68  $pageIdsToClear = [(int)$pageIdsToClear];
69  }
70  foreach ($pageIdsToClear as $pageId) {
71  $this->cacheManager->flushCachesInGroupByTag('pages', 'pageId_' . $pageId);
72  }
73  }
74  }
75 
83  {
84  if (!$this->pageIdStack->isEmpty()) {
85  $pageIds = [];
86  while (!$this->pageIdStack->isEmpty()) {
87  $pageIds[] = (int)$this->pageIdStack->pop();
88  }
89  $pageIds = array_values(array_unique($pageIds));
90  $this->clearPageCache($pageIds);
91  }
92  }
93 }
clearPageCache($pageIdsToClear=null)
injectCacheManager(\TYPO3\CMS\Core\Cache\CacheManager $cacheManager)