Skip to content

Commit

Permalink
[BUGFIX] Add hook to flush class cache
Browse files Browse the repository at this point in the history
This hook flushes the cache only if the environment is Development and the cacheCmd is 'all'
  • Loading branch information
garbast committed Nov 23, 2024
1 parent e8d8874 commit 4e2d629
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Classes/Cache/CacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Evoweb\Extender\Cache;

use Evoweb\Extender\Hooks\ClearCacheHook;
use TYPO3\CMS\Core\Cache\Backend\AbstractBackend;
use TYPO3\CMS\Core\Cache\Backend\FileBackend;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
Expand Down Expand Up @@ -52,5 +53,7 @@ public function createCache(string $identifier): ?FrontendInterface
public static function addClassCacheConfigToGlobalTypo3ConfVars(): void
{
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extender'] = static::$configuration;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc']['extender'] =
ClearCacheHook::class . '->';
}
}
23 changes: 23 additions & 0 deletions Classes/Hooks/ClearCacheHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Evoweb\Extender\Hooks;

use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend;
use TYPO3\CMS\Core\Core\Environment;

class ClearCacheHook
{
public function __construct(protected PhpFrontend $classCache)
{
}

/**
* @param array<non-empty-string, string|string[]> $parameters
*/
public function clearCachePostProc(array $parameters): void
{
if (Environment::getContext()->isDevelopment() && $parameters['cacheCmd'] === 'all') {
$this->classCache->flush();
}
}
}
2 changes: 0 additions & 2 deletions Classes/Loader/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

use Evoweb\Extender\Cache\ClassCacheManager;
use Evoweb\Extender\Configuration\ClassRegister;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend;
use TYPO3\CMS\Core\SingletonInterface;

Expand Down
5 changes: 5 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ services:
$container: '@service_container'
shared: false

Evoweb\Extender\Hooks\ClearCacheHook:
public: true
arguments:
$classCache: '@cache.extender'

Evoweb\Extender\Loader\ClassLoader:
arguments:
$classCache: '@cache.extender'
Expand Down

0 comments on commit 4e2d629

Please sign in to comment.