2 namespace TYPO3\CMS\Core\Cache;
17 use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheGroupException;
57 'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
58 'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class,
60 'groups' => array(
'all')
90 foreach ($cacheConfigurations as $identifier => $configuration) {
91 if (!is_array($configuration)) {
92 throw new \InvalidArgumentException(
'The cache configuration for cache "' . $identifier .
'" was not an array as expected.', 1231259656);
94 $this->cacheConfigurations[$identifier] = $configuration;
106 public function registerCache(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache)
108 $identifier = $cache->getIdentifier();
109 if (isset($this->caches[$identifier])) {
110 throw new \TYPO3\CMS\Core\Cache\Exception\DuplicateIdentifierException(
'A cache with identifier "' . $identifier .
'" has already been registered.', 1203698223);
112 $this->caches[$identifier] = $cache;
125 if ($this->
hasCache($identifier) ===
false) {
126 throw new \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException(
'A cache with identifier "' . $identifier .
'" does not exist.', 1203699034);
128 if (!isset($this->caches[$identifier])) {
131 return $this->caches[$identifier];
143 return isset($this->caches[$identifier]) || isset($this->cacheConfigurations[$identifier]);
155 foreach ($this->caches as $cache) {
171 if (isset($this->cacheGroups[$groupIdentifier])) {
172 foreach ($this->cacheGroups[$groupIdentifier] as $cacheIdentifier) {
173 if (isset($this->caches[$cacheIdentifier])) {
174 $this->caches[$cacheIdentifier]->flush();
195 if (isset($this->cacheGroups[$groupIdentifier])) {
196 foreach ($this->cacheGroups[$groupIdentifier] as $cacheIdentifier) {
197 if (isset($this->caches[$cacheIdentifier])) {
198 $this->caches[$cacheIdentifier]->flushByTag($tag);
218 foreach ($this->caches as $cache) {
219 $cache->flushByTag($tag);
243 $modifiedClassNamesWithUnderscores = array();
244 $objectClassesCache = $this->
getCache(
'FLOW3_Object_Classes');
245 $objectConfigurationCache = $this->
getCache(
'FLOW3_Object_Configuration');
246 switch ($fileMonitorIdentifier) {
247 case 'FLOW3_ClassFiles':
248 $modifiedAspectClassNamesWithUnderscores = array();
249 foreach ($changedFiles as $pathAndFilename => $status) {
250 $pathAndFilename = str_replace(FLOW3_PATH_PACKAGES,
'', $pathAndFilename);
252 if (preg_match(
'/[^\\/]+\\/(.+)\\/(Classes|Tests)\\/(.+)\\.php/', $pathAndFilename, $matches) === 1) {
253 $classNameWithUnderscores = str_replace(array(
'/',
'.'),
'_', $matches[1] .
'_' . ($matches[2] ===
'Tests' ?
'Tests_' :
'') . $matches[3]);
254 $modifiedClassNamesWithUnderscores[$classNameWithUnderscores] =
true;
256 if (substr($classNameWithUnderscores, -6, 6) ===
'Aspect') {
257 $modifiedAspectClassNamesWithUnderscores[$classNameWithUnderscores] =
true;
260 if (empty($modifiedAspectClassNamesWithUnderscores)) {
261 $objectClassesCache->remove($classNameWithUnderscores);
265 $flushDoctrineProxyCache =
false;
266 if (!empty($modifiedClassNamesWithUnderscores)) {
267 $reflectionStatusCache = $this->
getCache(
'FLOW3_Reflection_Status');
268 foreach ($modifiedClassNamesWithUnderscores as $classNameWithUnderscores => $_) {
269 $reflectionStatusCache->remove($classNameWithUnderscores);
270 if ($flushDoctrineProxyCache ===
false && preg_match(
'/_Domain_Model_(.+)/', $classNameWithUnderscores) === 1) {
271 $flushDoctrineProxyCache =
true;
274 $objectConfigurationCache->remove(
'allCompiledCodeUpToDate');
276 if (!empty($modifiedAspectClassNamesWithUnderscores)) {
277 $this->systemLogger->log(
'Aspect classes have been modified, flushing the whole proxy classes cache.', LOG_INFO);
278 $objectClassesCache->flush();
280 if ($flushDoctrineProxyCache ===
true) {
281 $this->systemLogger->log(
'Domain model changes have been detected, triggering Doctrine 2 proxy rebuilding.', LOG_INFO);
282 $objectConfigurationCache->remove(
'doctrineProxyCodeUpToDate');
285 case 'FLOW3_ConfigurationFiles':
286 $policyChangeDetected =
false;
287 $routesChangeDetected =
false;
288 foreach ($changedFiles as $pathAndFilename => $_) {
290 if (!in_array(
$filename, array(
'Policy.yaml',
'Routes.yaml'))) {
293 if ($policyChangeDetected ===
false &&
$filename ===
'Policy.yaml') {
294 $this->systemLogger->log(
'The security policies have changed, flushing the policy cache.', LOG_INFO);
295 $this->
getCache(
'FLOW3_Security_Policy')->flush();
296 $policyChangeDetected =
true;
297 }
elseif ($routesChangeDetected ===
false &&
$filename ===
'Routes.yaml') {
298 $this->systemLogger->log(
'A Routes.yaml file has been changed, flushing the routing cache.', LOG_INFO);
299 $this->
getCache(
'FLOW3_Mvc_Routing_FindMatchResults')->flush();
300 $this->
getCache(
'FLOW3_Mvc_Routing_Resolve')->flush();
301 $routesChangeDetected =
true;
304 $this->systemLogger->log(
'The configuration has changed, triggering an AOP proxy class rebuild.', LOG_INFO);
305 $objectConfigurationCache->remove(
'allAspectClassesUpToDate');
306 $objectConfigurationCache->remove(
'allCompiledCodeUpToDate');
307 $objectClassesCache->flush();
309 case 'FLOW3_TranslationFiles':
310 foreach ($changedFiles as $pathAndFilename => $status) {
312 if (preg_match(
'/\\/Translations\\/.+\\.xlf/', $pathAndFilename, $matches) === 1) {
313 $this->systemLogger->log(
'The localization files have changed, thus flushing the I18n XML model cache.', LOG_INFO);
314 $this->
getCache(
'FLOW3_I18n_XmlModelCache')->flush();
339 return $className ===
'' ? \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::TAG_CLASS : \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::TAG_CLASS . str_replace(
'\\',
'_', $className);
349 foreach ($this->cacheConfigurations as $identifier => $_) {
350 if (!isset($this->caches[$identifier])) {
364 if (isset($this->cacheConfigurations[$identifier][
'frontend'])) {
365 $frontend = $this->cacheConfigurations[$identifier][
'frontend'];
367 $frontend = $this->defaultCacheConfiguration[
'frontend'];
369 if (isset($this->cacheConfigurations[$identifier][
'backend'])) {
370 $backend = $this->cacheConfigurations[$identifier][
'backend'];
372 $backend = $this->defaultCacheConfiguration[
'backend'];
374 if (isset($this->cacheConfigurations[$identifier][
'options'])) {
375 $backendOptions = $this->cacheConfigurations[$identifier][
'options'];
377 $backendOptions = $this->defaultCacheConfiguration[
'options'];
381 if (isset($this->cacheConfigurations[$identifier][
'groups']) && is_array($this->cacheConfigurations[$identifier][
'groups'])) {
382 $assignedGroups = $this->cacheConfigurations[$identifier][
'groups'];
384 $assignedGroups = $this->defaultCacheConfiguration[
'groups'];
386 foreach ($assignedGroups as $groupIdentifier) {
387 if (!isset($this->cacheGroups[$groupIdentifier])) {
388 $this->cacheGroups[$groupIdentifier] = array();
390 $this->cacheGroups[$groupIdentifier][] = $identifier;
393 $this->cacheFactory->create($identifier, $frontend, $backend, $backendOptions);