Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使Symfony2中的容器缓存无效?_Php_Symfony - Fatal编程技术网

Php 如何使Symfony2中的容器缓存无效?

Php 如何使Symfony2中的容器缓存无效?,php,symfony,Php,Symfony,我的Symfony应用程序配置的一部分是从旧数据库加载的,所以有时我需要使容器缓存失效以使用更新的数据 是否有任何API以编程方式使Symfony容器缓存无效 根据cacheclear命令: $filesystem = $this->container->get('filesystem'); $realCacheDir = $this->container->getParameter('kernel.cache_dir'); $this->container-&

我的Symfony应用程序配置的一部分是从旧数据库加载的,所以有时我需要使容器缓存失效以使用更新的数据

是否有任何API以编程方式使Symfony容器缓存无效

  • 根据cacheclear命令:

    $filesystem   = $this->container->get('filesystem');
    $realCacheDir = $this->container->getParameter('kernel.cache_dir');
    $this->container->get('cache_clearer')->clear($realCacheDir);
    $filesystem->remove($realCacheDir);
    
  • 直接从代码中调用cacheclear命令:

    services.yml

    clear_cache_command_service:
        class: Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand
        calls:
           - [setContainer, ["@service_container"] ]
    
    这样做是可能的(请注意,这将预热缓存):

  • $clearCacheCommand = $this->container->get('clear_cache_command_service');
    $clearCacheCommand->run(new ArgvInput(), new ConsoleOutput());