-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[2.7][Translation] added message cache. #13986
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
aitboudad
commented
Mar 19, 2015
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Fixed tickets | #13948, #2570, #13676 |
Tests pass? | yes |
License | MIT |
- tests
- add MessageDoctrineCache
@@ -76,11 +70,15 @@ class Translator implements TranslatorInterface, TranslatorBagInterface | |||
* | |||
* @api | |||
*/ | |||
public function __construct($locale, MessageSelector $selector = null, $cacheDir = null, $debug = false) | |||
public function __construct($locale, MessageSelector $selector = null, $cache = null, $debug = false) |
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.
The docblock needs to be changed to take into account that $cache
can be an instance of MessageCacheInterface
.
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.
fixed
e20e348
to
40f2628
Compare
I think this could be a nice addition for 2.7, the default cache is useful in 80% of apps but when the size of catalogue became more than 10 MB it's consumes too much memory. #config.yml
framework:
translator: { fallbacks: [en], cache: translation.cache.doctrine }
doctrine_cache:
providers:
translation_cache:
memcached:
servers:
localhost: 11211 #services.yml
translation.cache.doctrine:
class: Symfony\Component\Translation\DoctrineMessageCache
arguments: [%kernel.debug%, @translation_cache] https://blackfire.io/profiles/compare/82c496fe-200a-451d-a2c8-e2fd458f0193/graph /cc @fabpot |
b39dd88
to
45882cd
Compare
@Tobion can you review this PR ? |
45882cd
to
b17354f
Compare
@@ -152,5 +153,13 @@ | |||
<service id="translation.extractor" class="%translation.extractor.class%"/> | |||
|
|||
<service id="translation.writer" class="%translation.writer.class%"/> | |||
|
|||
<!-- Cache --> | |||
<service id="translation.cache.default" class="Symfony\Component\Translation\MessageCache" public="false"> |
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.
You can make this service private. Then it could be inlined or removed by the compiler.
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.
isn't it ?
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.
Yes it is already. Sorry.
ping @symfony/deciders |
@@ -652,6 +652,10 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder | |||
|
|||
$container->setParameter('translator.logging', $config['logging']); | |||
|
|||
if (isset($config['cache']) && $config['cache']) { |
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.
Isn't isset($config['cache'])
alone sufficient enough?
b17354f
to
dfd828f
Compare
any feedback, I really want it to be available in 2.7 :) |
👍 |
d375b6d
to
803e7d9
Compare
|
||
<!-- Cache --> | ||
<service id="translation.cache.default" class="Symfony\Component\Translation\MessageCache" public="false"> | ||
<argument key="cache_dir">%kernel.cache_dir%/translations</argument> <!-- cache_dir --> |
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.
The key
can be removed as it's not used.
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.
fixed
803e7d9
to
eb33493
Compare
* @param bool $debug Use cache in debug mode ? | ||
* @param string $locale The locale | ||
* @param MessageSelector|null $selector The message selector for pluralization | ||
* @param string|null|MessageCacheInterface $cache The directory to use for the cache |
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.
the description is not accurate anymore
I tend to agree with @mpdude |
anyway the main thing here is to provide a doctrine cache for translation, what I didn't like for ConfigCache is it mainly related to resource file. |
any decision about this feature the current implementation look good to me :), |
#14178 tries to solve a completely different problem. But even with sticking to the current way of using |
cbd6c79
to
f5c9a3d
Compare
If I got the code right (not sure about that), your goal is to keep messages in a key-value-store type cache. That way, the Also, the message catalogue will mostly be kept in shared memory and reduce the memory footprint for a single PHP process. With the current implementation, the entire Catalogue will be read from the So, if this understanding is correct, can't we find a way to make the Translator (key-value-)cache aware and use a lookup strategy based on (locale, domain, message-id) without having to touch the Here's the steps such a Translator would need to do:
Does that make sense? |
@@ -659,6 +659,10 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder | |||
|
|||
$container->setParameter('translator.logging', $config['logging']); | |||
|
|||
if (isset($config['cache'])) { |
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.
You should prefix cache entries with something specific with the current installation to prevent conflicts if several Symfony apps run on the same server.
The example for the validator: https://github.com/aitboudad/symfony/blob/translation_catalogue_cache/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L774
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.
fixed.
@mpdude you understand this topic now better than me :) , below my answers:
The main think here for me is to move the cache outside of Translator and adding an initial implementation of key-value-store(doctrine/cache).
Right I think missed this part even if we use key-value-store we need ``ConfigCache` to make cache aware better. |
f5c9a3d
to
af78b62
Compare
@mpdude Hi, So what I made now with 69225b8 is refresh cache when resources file change. And to understand how I make the Translator (key-value-)cache aware:
check whether the requested (locale, domain, message-id) is available in the (key-value-)cache
If that key is missing, re-populate the key-value-cache with the MessageCatalogue loaded from the Loaders and not ConfigCache ! |
69225b8
to
2860af4
Compare
If you're trying to go without My suggestion was to keep the In other words, the When you have the Catalogue at hand anyways (because you had to rebuild it or load it because the message was not in DoctrineCache), also save it to the DoctrineCache. |
2860af4
to
0df4e75
Compare
I'd hold off and do not merge this into 2.7. Note that I didn't review this PR in details just yet, and I only scanned through comments. Forgive me if I'm repeating someone else here. We need to think of how to organise doctrine integration more carefully and make it consistent across the framework. With the current implementation I don't think that doctrine cache classes belong to the Doctrine bridge, as they're only use is the translator. Serializer and Validator have their own cache implementations, slightly different from each other - first relies on doctrine/cache directly, the later adapts its interface. This PR introduces yet another approach. All I'm saying we should stop and consider if we can make it a bit more consistent. |
0df4e75
to
d1b1986
Compare
d1b1986
to
4794d8b
Compare
The safe way is to split this PR into 2, let's discuss about adding message cache interface and once accepted I'll open another one for doctrine cache. |
…ion for validator mapping (jakzal) This PR was merged into the 2.8 branch. Discussion ---------- [FrameworkBundle] Add a doctrine cache service definition for validator mapping | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | symfony/symfony-docs#5409 Following #12975, this PR only registers a new service so it's possible to use the new doctrine based cache implementation instead of the deprecated one. To use it, the end user would need to configure it in his `config.yml`: ```yaml framework: validation: cache: validator.mapping.cache.doctrine.apc ``` In 3.0 we'll be able to replace the deprecated definition by aliasing `validator.mapping.cache.apc` to `validator.mapping.cache.doctrine.apc`. I thought of automatic wrapping of services which implement doctrine interface, but decided it would be too magic. I'm not convinced if APC is a good default anymore and hope for some discussion. I've used it as it's also used in serializer, and probably translation (see #13986). Since there's a built in opcache in more recent PHP versions, and apcu doesn't seem to be stable, there are better choices. Perhaps a better default would be a filesystem cache (not better performing, but it works anywhere). Commits ------- 0642911 [FrameworkBundle] Add a doctrine cache service definition for validator mapping