‪TYPO3CMS  10.4
CacheService.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 
28 {
32  protected ‪$pageIdStack;
33 
37  protected ‪$cacheManager;
38 
43  {
44  $this->cacheManager = ‪$cacheManager;
45  }
46 
50  public function ‪__construct()
51  {
52  $this->pageIdStack = new \SplStack();
53  }
54 
58  public function ‪getPageIdStack(): \SplStack
59  {
60  return ‪$this->pageIdStack;
61  }
62 
68  public function ‪clearPageCache($pageIdsToClear = null): void
69  {
70  if ($pageIdsToClear === null) {
71  $this->cacheManager->flushCachesInGroup('pages');
72  } else {
73  if (!is_array($pageIdsToClear)) {
74  $pageIdsToClear = [(int)$pageIdsToClear];
75  }
76  $tags = array_map(function ($item) {
77  return 'pageId_' . $item;
78  }, $pageIdsToClear);
79  $this->cacheManager->flushCachesInGroupByTags('pages', $tags);
80  }
81  }
82 
87  public function ‪clearCachesOfRegisteredPageIds(): void
88  {
89  if (!$this->pageIdStack->isEmpty()) {
90  $pageIds = [];
91  while (!$this->pageIdStack->isEmpty()) {
92  $pageIds[] = (int)$this->pageIdStack->pop();
93  }
94  $pageIds = array_values(array_unique($pageIds));
95  $this->‪clearPageCache($pageIds);
96  }
97  }
98 }
‪TYPO3\CMS\Extbase\Service
Definition: CacheService.php:18
‪TYPO3\CMS\Extbase\Service\CacheService\injectCacheManager
‪injectCacheManager(CacheManager $cacheManager)
Definition: CacheService.php:40
‪TYPO3\CMS\Extbase\Service\CacheService\$pageIdStack
‪SplStack $pageIdStack
Definition: CacheService.php:31
‪TYPO3\CMS\Extbase\Service\CacheService\clearPageCache
‪clearPageCache($pageIdsToClear=null)
Definition: CacheService.php:66
‪TYPO3\CMS\Extbase\Service\CacheService\getPageIdStack
‪SplStack getPageIdStack()
Definition: CacheService.php:56
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Extbase\Service\CacheService\$cacheManager
‪TYPO3 CMS Core Cache CacheManager $cacheManager
Definition: CacheService.php:35
‪TYPO3\CMS\Extbase\Service\CacheService\clearCachesOfRegisteredPageIds
‪clearCachesOfRegisteredPageIds()
Definition: CacheService.php:85
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\Extbase\Service\CacheService
Definition: CacheService.php:28
‪TYPO3\CMS\Extbase\Service\CacheService\__construct
‪__construct()
Definition: CacheService.php:48