我有一个在Symfony 4上运行的应用程序。我使用文件系统缓存组件。我想创建一个清空它的函数,但是不幸的是,我的整个应用程序现在坏了。所有页面将永远永远加载。
在我执行的脚本下面:
<?php
namespace App\Controller\Admin;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Cache\Simple\FilesystemCache;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\Instelling;
class AdminInstellingController extends AbstractController
{
/**
* @Route("/beheer/cache-clear")
*/
public function clearCache()
{
$cache = new FilesystemCache();
$cache->clear();
$this->addFlash("success", "De <strong>CRM DataServer</strong> cache is succesvol geleegd.");
// return $this->redirect('/beheer/dashboard');
}
}
我已经删除了我的var / cache文件夹,默认情况下用于存储该缓存的temp文件夹(sys_get_temp_dir),重新安装了供应商,清空了Cookie和缓存并重新启动了计算机。什么都没用,应用程序不断加载。我该怎么办才能解决此问题?
这不是从控制器内部清除缓存的好方法。您应该创建一个命令并通过命令行清除缓存
php bin/console make:command app:clear-filesystem-cache
并在其中写入缓存清除功能
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$cache = new FilesystemCache();
$cache->clear();
$io->success('De CRM DataServer cache is succesvol geleegd.');
return 0;
}
然后使用此命令清除缓存。
php bin/console app:clear-filesystem-cache
如果要在控制器中实现此目标,则将php.ini中的max-execution-time
增加到30秒以上。