I'm using Symfony2 (soon 3), and we got some translations that are stored in the Database. This means that when we run cache:clear the translations are fetched from the database and stored in the cache (on disk). This also means users can change the translations directly in the database, but those changes aren't visible immediately.
Is there a way to only clear the translation cache files in Symfony? Without refreshing the whole cache?
I do this so
$cacheDir = dirname($this->getParameter('kernel.cache_dir'));
foreach (['prod', 'dev'] as $env) {
array_map('unlink', glob("$cacheDir/$env/translations/*"));
}
Just to complete answers already provided, removing the translations folder in cache/ won't be enough if you need to take new translation files into account.
For that, you'll need to also remove the file caching the path of all ressources and asset file.
Its name depends on the environment: appDevDebugProjectContainer.php or appProdProjectContainer.php.
So based on @Atmarama answer:
$cacheDir = dirname($this->getParameter('kernel.cache_dir'));
foreach (['prod', 'dev'] as $env) {
array_map('unlink', glob("$cacheDir/$env/translations/*"));
array_map('unlink', glob("$cacheDir/$env/app*ProjectContainer.php"));
}
Tested with Symfony 3.3.x.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With