How to invalidate container cache in Symfony2?

前端 未结 1 1446
执念已碎
执念已碎 2020-12-18 09:02

Part of my Symfony app configuration is being loaded from legacy database, so sometimes I need to invalidate container cache to make use of updated data.

Is there an

1条回答
  •  一生所求
    2020-12-18 09:21

    1. As per CacheClearCommand:

      $filesystem   = $this->container->get('filesystem');
      $realCacheDir = $this->container->getParameter('kernel.cache_dir');
      $this->container->get('cache_clearer')->clear($realCacheDir);
      $filesystem->remove($realCacheDir);
      
    2. Directly call CacheClearCommand from code:

      services.yml

      clear_cache_command_service:
          class: Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand
          calls:
             - [setContainer, ["@service_container"] ]
      

      Than it's possible to do something like this (note that this will warmup the cache):

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

    0 讨论(0)
提交回复
热议问题