|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class description |
|
4
|
|
|
* |
|
5
|
|
|
* @package CacheCheck\Service |
|
6
|
|
|
* @author Julian Seitz |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace HDNET\CacheCheck\Service; |
|
10
|
|
|
|
|
11
|
|
|
use TYPO3\CMS\Core\Cache\CacheManager; |
|
12
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
13
|
|
|
use TYPO3\CMS\Extbase\Reflection\ClassReflection; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class CacheRegistry |
|
17
|
|
|
*/ |
|
18
|
|
|
class CacheRegistry extends AbstractService |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Register cache file |
|
23
|
|
|
*/ |
|
24
|
|
|
const FILE_NAME = 'typo3temp/cache_check.txt'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Not changeable caches |
|
28
|
|
|
* |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $nonChangeableCaches = []; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Collect non changeable caches |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct() |
|
37
|
|
|
{ |
|
38
|
|
|
$manager = GeneralUtility::makeInstance(CacheManager::class); |
|
39
|
|
|
|
|
40
|
|
|
$classReflection = new ClassReflection(get_class($manager)); |
|
41
|
|
|
$this->nonChangeableCaches = array_keys($classReflection->getProperty('caches') |
|
42
|
|
|
->getValue($manager)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get the not changeable caches |
|
47
|
|
|
* |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getNonChangeableCaches() |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->nonChangeableCaches; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Add the given cache to the registry |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $cacheName |
|
59
|
|
|
*/ |
|
60
|
|
|
public function add($cacheName) |
|
61
|
|
|
{ |
|
62
|
|
|
$entries = $this->getCurrent(); |
|
63
|
|
|
$entries[] = $cacheName; |
|
64
|
|
|
GeneralUtility::writeFile($this->getFileName(), serialize($entries)); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Remove the cache with the given key |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $cacheName |
|
71
|
|
|
*/ |
|
72
|
|
|
public function remove($cacheName) |
|
73
|
|
|
{ |
|
74
|
|
|
$entries = $this->getCurrent(); |
|
75
|
|
|
$key = array_search($cacheName, $entries); |
|
76
|
|
|
if ($key !== false) { |
|
77
|
|
|
unset($entries[$key]); |
|
78
|
|
|
GeneralUtility::writeFile($this->getFileName(), serialize($entries)); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Get the current active caches |
|
84
|
|
|
* |
|
85
|
|
|
* @return array |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getCurrent() |
|
88
|
|
|
{ |
|
89
|
|
|
$activeCaches = unserialize(GeneralUtility::getUrl($this->getFileName())); |
|
90
|
|
|
return !is_array($activeCaches) ? [] : $activeCaches; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* returns absolute file name |
|
95
|
|
|
* |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
protected function getFileName() |
|
99
|
|
|
{ |
|
100
|
|
|
return GeneralUtility::getFileAbsFileName(self::FILE_NAME); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|