Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
Nov 6, 2019

Conversation

fancyweb
Copy link
Contributor

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.

@fancyweb fancyweb force-pushed the translation-invalidate-cache branch from 859b50b to 6cbee09 Compare October 26, 2019 10:44
@nicolas-grekas nicolas-grekas added this to the 4.3 milestone Oct 27, 2019
@@ -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 = [])
Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

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.

@fabpot
Copy link
Member

fabpot commented Nov 6, 2019

Thank you @fancyweb.

fabpot added a commit that referenced this pull request Nov 6, 2019
…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
@fabpot fabpot merged commit 6cbee09 into symfony:4.3 Nov 6, 2019
@fancyweb fancyweb deleted the translation-invalidate-cache branch November 7, 2019 08:10
@fabpot fabpot mentioned this pull request Nov 11, 2019
fabpot added a commit that referenced this pull request Nov 17, 2019
… 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants