Php 我的应用程序在尝试清除FilesystemCache后继续加载
我有一个在Symfony 4上运行的应用程序。我使用文件系统缓存组件。我想创建一个清空它的函数,但不幸的是,我的整个应用程序现在都坏了。所有页面将永远继续加载 下面是我执行的脚本:Php 我的应用程序在尝试清除FilesystemCache后继续加载,php,symfony,caching,symfony4,Php,Symfony,Caching,Symfony4,我有一个在Symfony 4上运行的应用程序。我使用文件系统缓存组件。我想创建一个清空它的函数,但不幸的是,我的整个应用程序现在都坏了。所有页面将永远继续加载 下面是我执行的脚本: <?php namespace App\Controller\Admin; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Cache\Simple\FilesystemCach
<?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');
}
}
从控制器内部清除缓存不是一个好方法。 您应该创建一个命令并通过命令行清除缓存
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中的
最大执行时间增加到30秒以上。最好的方法是实现控制台命令,但对于快速测试,可以简单地更改控制器中的时间限制,而不是php.ini中的全局更改:
public function clearCache()
{
// set_time_limit ( int $seconds ) : bool
set_time_limit(300);
//...
}