‪TYPO3CMS  9.5
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 
22 {
26  protected ‪$pageIdStack;
27 
31  protected ‪$cacheManager;
32 
36  public function ‪injectCacheManager(\‪TYPO3\CMS\Core\Cache\CacheManager ‪$cacheManager)
37  {
38  $this->cacheManager = ‪$cacheManager;
39  }
40 
44  public function ‪__construct()
45  {
46  $this->pageIdStack = new \SplStack;
47  }
48 
52  public function ‪getPageIdStack()
53  {
54  return ‪$this->pageIdStack;
55  }
56 
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  $tags = array_map(function ($item) {
71  return 'pageId_' . $item;
72  }, $pageIdsToClear);
73  $this->cacheManager->flushCachesInGroupByTags('pages', $tags);
74  }
75  }
76 
81  public function ‪clearCachesOfRegisteredPageIds()
82  {
83  if (!$this->pageIdStack->isEmpty()) {
84  $pageIds = [];
85  while (!$this->pageIdStack->isEmpty()) {
86  $pageIds[] = (int)$this->pageIdStack->pop();
87  }
88  $pageIds = array_values(array_unique($pageIds));
89  $this->‪clearPageCache($pageIds);
90  }
91  }
92 }
‪TYPO3
‪TYPO3\CMS\Extbase\Service
Definition: CacheService.php:2
‪TYPO3\CMS\Extbase\Service\CacheService\injectCacheManager
‪injectCacheManager(\TYPO3\CMS\Core\Cache\CacheManager $cacheManager)
Definition: CacheService.php:34
‪TYPO3\CMS\Extbase\Service\CacheService\$pageIdStack
‪SplStack $pageIdStack
Definition: CacheService.php:25
‪TYPO3\CMS\Extbase\Service\CacheService\clearPageCache
‪clearPageCache($pageIdsToClear=null)
Definition: CacheService.php:60
‪TYPO3\CMS\Extbase\Service\CacheService\getPageIdStack
‪SplStack getPageIdStack()
Definition: CacheService.php:50
‪TYPO3\CMS\Extbase\Service\CacheService\$cacheManager
‪TYPO3 CMS Core Cache CacheManager $cacheManager
Definition: CacheService.php:29
‪TYPO3\CMS\Extbase\Service\CacheService\clearCachesOfRegisteredPageIds
‪clearCachesOfRegisteredPageIds()
Definition: CacheService.php:79
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Extbase\Service\CacheService
Definition: CacheService.php:22
‪TYPO3\CMS\Extbase\Service\CacheService\__construct
‪__construct()
Definition: CacheService.php:42