-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle][Translation] Invalidate cached catalogues when the scanned directories change #34129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…scanned directories change
859b50b
to
6cbee09
Compare
@@ -86,7 +88,7 @@ class Translator implements LegacyTranslatorInterface, TranslatorInterface, Tran | |||
/** | |||
* @throws InvalidArgumentException If a locale contains invalid characters | |||
*/ | |||
public function __construct(?string $locale, MessageFormatterInterface $formatter = null, string $cacheDir = null, bool $debug = false) | |||
public function __construct(?string $locale, MessageFormatterInterface $formatter = null, string $cacheDir = null, bool $debug = false, array $cacheVary = []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking at this again an I'm not sure if we can add a new constructor arg on 4.3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as it's added with a default value at the end, I think yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although it would look like a new feature.
Thank you @fancyweb. |
…s when the scanned directories change (fancyweb) This PR was merged into the 4.3 branch. Discussion ---------- [FrameworkBundle][Translation] Invalidate cached catalogues when the scanned directories change | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #33992 | License | MIT | Doc PR | - The cache file name needs to depend on the scanned directories list. Otherwise, when a new directory is added, even if the container is rebuilt and the `FWB Translator` gets the new scanned directories list, the cached catalogue name is still the same and is resolved accordingly. An alternative would be to make the `Translation Translator` `getCatalogueCachePath()` method and `fallbackLocales` `@internal` and `protected` to just override everything in the `FWB Translator`. The `cacheVary` argument has the benefit to be reusable by all the `Translation` component users. Note that there is a negative minor performance impact that increases when the list of scanned directories grows. Commits ------- 6cbee09 [FrameworkBundle][Translation] Invalidate cached catalogues when the scanned directories change
… vary scanned directories (fancyweb) This PR was merged into the 4.3 branch. Discussion ---------- [FrameworkBundle] Remove project dir from Translator cache vary scanned directories | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Closes #34395 | License | MIT | Doc PR | - Weird cases such as having different paths for directories found through reflection (cf https://github.com/symfony/symfony/blob/8522a88185a7e283ad342b3539cd088d76968df9/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L1105) or using different values on warmup and run for another parameter than `kernel.project_dir` are still unconvered. Unfortunately there is nothing we can do, do we care? If yes, then we might just wanna enable #34129 when the `debug` option is on. Commits ------- e75e01d [FrameworkBundle] Remove project dir from Translator cache vary scanned directories
The cache file name needs to depend on the scanned directories list. Otherwise, when a new directory is added, even if the container is rebuilt and the
FWB Translator
gets the new scanned directories list, the cached catalogue name is still the same and is resolved accordingly.An alternative would be to make the
Translation Translator
getCatalogueCachePath()
method andfallbackLocales
@internal
andprotected
to just override everything in theFWB Translator
. ThecacheVary
argument has the benefit to be reusable by all theTranslation
component users.Note that there is a negative minor performance impact that increases when the list of scanned directories grows.