TYPO3 CMS  TYPO3_8-7
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 
61  public function clearPageCache($pageIdsToClear = null)
62  {
63  if ($pageIdsToClear === null) {
64  $this->cacheManager->flushCachesInGroup('pages');
65  } else {
66  if (!is_array($pageIdsToClear)) {
67  $pageIdsToClear = [(int)$pageIdsToClear];
68  }
69  $tags = array_map(function ($item) {
70  return 'pageId_' . $item;
71  }, $pageIdsToClear);
72  $this->cacheManager->flushCachesInGroupByTags('pages', $tags);
73  }
74  }
75 
81  {
82  if (!$this->pageIdStack->isEmpty()) {
83  $pageIds = [];
84  while (!$this->pageIdStack->isEmpty()) {
85  $pageIds[] = (int)$this->pageIdStack->pop();
86  }
87  $pageIds = array_values(array_unique($pageIds));
88  $this->clearPageCache($pageIds);
89  }
90  }
91 }
clearPageCache($pageIdsToClear=null)
injectCacheManager(\TYPO3\CMS\Core\Cache\CacheManager $cacheManager)