Fix #493 - Improve Cache Clear Speed

This commit is contained in:
o.smith 2024-05-24 10:09:09 +01:00 committed by Jack Anderson
parent e3e9956e12
commit 08f3f07432
3 changed files with 66 additions and 5 deletions

View file

@ -29,7 +29,13 @@ $classicview_routing_exclusions = [
'any' => [
'ShowDuplicates'
],
'administration' => [
'upgrade',
'repair'
],
'Administration' => [
'upgrade',
'repair',
'UpgradeWizard_prepare',
'UpgradeWizard_commit'
],

View file

@ -128,11 +128,49 @@ class RepairAndClear

/////////////OLD

public function clearCoreCache()
/**
* Clear Symfony Cache
* @return void
*/
public function clearCoreCache() : void
{
if (empty($GLOBALS['installing'])) {
$coreCachePath = __DIR__ . '/../../../../cache/';
rmdir_recursive($coreCachePath);
$fs = new Symfony\Component\Filesystem\Filesystem();
$tempId = uniqid();

$this->clearCacheDir($fs, $tempId, '/prod');
$this->clearCacheDir($fs, $tempId, '/dev');
$this->clearCacheDir($fs, $tempId, '/test');
$this->clearCacheDir($fs, $tempId, '/qa');

require_once "include/portability/Services/Cache/CacheManager.php";
(new CacheManager())->markAsNeedsUpdate('rebuild_all');

if (function_exists('opcache_reset')) {
opcache_reset();
}

if (function_exists('apcu_clear_cache')) {
apcu_clear_cache();
}
}
}

/**
* Rename and remove cache subdirectory
* @param $fs
* @param $tempId
* @param $cacheFolder
* @return void
*/
protected function clearCacheDir($fs, $tempId, $cacheFolder) : void
{
$cacheDirPath = __DIR__ . '/../../../../cache' . $cacheFolder;

if($fs->exists($cacheDirPath)){
$fs->rename($cacheDirPath, $cacheDirPath . '_' . $tempId . '_deprecated/');
$fs->mkdir($cacheDirPath);
$fs->remove($cacheDirPath . '_' . $tempId . '_deprecated/');
}
}