Reputation: 1470
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?
Upvotes: 4
Views: 6004
Reputation: 3807
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.
Upvotes: 2
Reputation: 2623
I do this so
$cacheDir = dirname($this->getParameter('kernel.cache_dir'));
foreach (['prod', 'dev'] as $env) {
array_map('unlink', glob("$cacheDir/$env/translations/*"));
}
Upvotes: 3
Reputation: 17166
Running ./bin/console cache:clear
does not provide any options as to which cache folder should be removed. It just clears the complete folder and only handling warmup is configurable using options. For reference see the CacheClearCommand in the FrameworkBundle.
You could write your own command though that only checks for the translation-cache dir and clears it. By default it resides in a subfolder translations/
which should be easily accessible with a finder like this:
$finder = (new Finder)->in($cacheDir.'/'.$env)->directories()->name('translations');
foreach ($finder as $translationsDir) {
rmdir($translationDir->getPathname();
}
Upvotes: 0