首页 > 解决方案 > 尝试清除 FilesystemCache 后,我的应用程序继续加载

问题描述

我有一个在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 和缓存并重新启动了我的计算机。根本没有任何作用,应用程序一直在加载。我该怎么做才能解决这个问题?

标签: phpsymfonycachingsymfony4

解决方案


从控制器内部清除缓存不是一个好方法。您应该通过命令行创建命令并清除缓存

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

如果你想在控制器中实现这一点,那么将max-execution-timephp.ini 增加到 30 秒以上。


推荐阅读