【问题标题】:My application keeps loading after trying to clear FilesystemCache尝试清除 FilesystemCache 后,我的应用程序继续加载
【发布时间】:2020-06-22 07:13:06
【问题描述】:

我有一个在 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 symfony caching symfony4


    【解决方案1】:

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

    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 秒以上。

    【讨论】:

      【解决方案2】:

      最好的方法是实现控制台命令,但为了快速测试,可以直接在控制器中更改时间限制与在 php.ini 中进行全局更改:

      public function clearCache()
      {
        //  set_time_limit ( int $seconds ) : bool
        set_time_limit(300);
        //...
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-02-20
        • 2016-10-05
        • 1970-01-01
        • 2015-01-06
        • 1970-01-01
        • 2019-03-31
        • 2017-05-30
        相关资源
        最近更新 更多