我的部分Symfony应用程序配置是从旧数据库加载的,因此有时我需要使容器缓存无效以使用更新的数据.
是否有任何API可以通过编程方式使Symfony容器缓存失效?
Tro*_*ggy 10
按照CacheClearCommand:
$filesystem = $this->container->get('filesystem');
$realCacheDir = $this->container->getParameter('kernel.cache_dir');
$this->container->get('cache_clearer')->clear($realCacheDir);
$filesystem->remove($realCacheDir);
Run Code Online (Sandbox Code Playgroud)直接从代码中调用CacheClearCommand:
services.yml
clear_cache_command_service:
class: Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand
calls:
- [setContainer, ["@service_container"] ]
Run Code Online (Sandbox Code Playgroud)
可能会做这样的事情(注意这将预热缓存):
$clearCacheCommand = $this->container->get('clear_cache_command_service');
$clearCacheCommand->run(new ArgvInput(), new ConsoleOutput());
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
3200 次 |
| 最近记录: |