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

Skip to content

Add new translation files without clearing the cache #27600

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

Closed
javiereguiluz opened this issue Jun 14, 2018 · 6 comments
Closed

Add new translation files without clearing the cache #27600

javiereguiluz opened this issue Jun 14, 2018 · 6 comments

Comments

@javiereguiluz
Copy link
Member

Description
Don't require to clear cache when adding new translation files.

Example
If you add a new translation file, the app won't use it unless you clear the cache entirely. This is cumbersome and inconsistent with other parts of the framework.

Is there any tech constraint that prevents us from checking if there are new files in the translations/ dir and load them automatically (in dev)?

@welcoMattic
Copy link
Member

Hi! I had a real-life case for this feature with php-translation/symfony-bundle.

With @damienalexandre and @lyrixx, we opened an issue to explain our case here.

@stof
Copy link
Member

stof commented Jun 14, 2018

Well, the handling of translation files is done in 2 steps, both with caching:

  • the list of files is built by the DI extension and stored in the service definition (cached by the container cache). This layer should already handle invalidation of the container cache when you add a new translation
  • the translation catalogue is cached by the translation component. The different loaded files are used as resources for cache invalidation there. But I don't think the cache gets invalidated if the list of resources in the Translator gets changed compared to the one when dumping the cache.

I think it could be possible to add a new resource in the message catalogue cache checking freshness based on the list of resources in the translator (but it might be hard if this list of resources is maintained by a different object. I don't remember how the architecture works exactly in 4.1 as this changed over time in Symfony)

@stof
Copy link
Member

stof commented Jun 14, 2018

@welcoMattic your issue is different, as this is not about a debug mode, but about a prod mode. Your issue is related to the DI-level caching, because you tried to avoid clearing the container cache.
But moving the detection of translation files are runtime rather than at compile-time may have an impact on performance (and would require changing entirely the way resources are working in the component if you don't want to run the finder on each instantiation, as a directory resource would not be associated to a domain and locale).

@nicolas-grekas
Copy link
Member

There's something I don't get here. @javiereguiluz and @stof gave what I understand as conflicting sentences:

Is there any tech constraint that prevents us from checking if there are new files [...] (in dev)?
and
This layer should already handle invalidation of the container cache when you add a new translation

Who is right?
From what I understand, @welcoMattic has a different issue than the one described by @javiereguiluz, since it is prod-only (if @stof is right?)

@apfelbox
Copy link
Contributor

apfelbox commented Jun 18, 2018

@nicolas-grekas I can confirm that newly added translation files in dev won't work until you manually clear the cache. So the comment from @stof describes the supposed state and not the current state.

Tested in 4.1.0

@stof
Copy link
Member

stof commented Apr 1, 2019

I'm not describind the supposed state. If you read my first comment, you will see that the second bullet point precisely describes where the invalidation is not done properly.

@fabpot fabpot closed this as completed Apr 6, 2019
fabpot added a commit that referenced this issue Apr 6, 2019
This PR was squashed before being merged into the 4.3-dev branch (closes #28937).

Discussion
----------

Improve Translator caching

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27600
| License       | MIT
| Doc PR        | N/A

Add DirectoryResources to MessageCatalogues when loaded.

So that when a file is added to one of the directories the cache for all MessageCatalogues will be invalidated.

All directories must be added to all MessageCatalogues because we can't predict for which locale files will be added to each individual directory.

Also, now that the translator keeps track of its own directories for caching the container no longer needs to it. This means that when a translation changes or is added the container no longer needs to be fully rebuilt, saving a considerable amount of time (compilation time went down from ~4 seconds to ~1 second on each translation change/add in our project).

Commits
-------

a524658 Improve Translator caching
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants