[英]How to invalidate container cache in Symfony2?
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. 我的部分Symfony应用程序配置是从旧数据库加载的,因此有时我需要使容器缓存无效以使用更新的数据。
Is there any API to invalidate Symfony container cache programmatically? 是否有任何API可以通过编程方式使Symfony容器缓存失效?
As per CacheClearCommand
: 根据CacheClearCommand
:
$filesystem = $this->container->get('filesystem'); $realCacheDir = $this->container->getParameter('kernel.cache_dir'); $this->container->get('cache_clearer')->clear($realCacheDir); $filesystem->remove($realCacheDir);
Directly call CacheClearCommand from code: 直接从代码中调用CacheClearCommand:
services.yml 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());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.