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 any API to invalidate Symfony container cache programmatically?
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);
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());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.