php - 尝试清除 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 和缓存并重新启动了我的计算机。根本没有任何作用,应用程序一直在加载。我该怎么做才能解决这个问题?
解决方案
从控制器内部清除缓存不是一个好方法。您应该通过命令行创建命令并清除缓存
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-time
php.ini 增加到 30 秒以上。
推荐阅读
- javascript - 视频结束时显示按钮
- database - 有没有办法手动锁定/解锁 PostgreSQL 中不依赖事务的表行?
- c# - 有效地将字符串编码为流
- c# - 如何在 aspx.cs 文件的 App_Code 文件夹中调用 .cs 文件中的方法?
- c++ - const 限定模板值的用途
- sql - SQL 中 SPLIT 上的条件 OFFSET
- javascript - 从 jQuery .css() 函数添加时 translateY 不起作用
- python-3.x - 如何有效地从线索中生成所有可能的二进制字符串?
- spring - 当在 master 的应用程序属性文件中设置 server.port 属性时,Spring Cloud Deployer Local 无法启动工作人员远程分区
- c - 使用编程语言 C 测试 Arduino Board 的引脚