-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] integrate the Cache component #18371
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
<service id="cache.adapter.apcu" class="Symfony\Component\Cache\Adapter\ApcuAdapter" abstract="true"> | ||
<tag name="cache.pool" namespace-arg-index="0" default-lifetime-arg-index="1" /> | ||
<argument /> <!-- namespace --> | ||
<argument /> <!-- default lifetime --> |
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.
In other services namespace
is third argument but here is first. Maybe better change constructor signature for better consistency?
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.
But default lifetime is always second...
|
||
<service id="cache.adapter.doctrine" class="Symfony\Component\Cache\Adapter\DoctrineAdapter" abstract="true"> | ||
<tag name="cache.pool" service-provider-arg-index="0" default-lifetime-arg-index="1" namespace-arg-index="2" /> | ||
<argument /> <!-- doctrine provider service --> |
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.
Doctrine
I am not convinced that people will need to create services starting with Besides that I am 👍 on the current state of this feature. |
ping @symfony/deciders |
c4a89ff
to
b0a2860
Compare
@xabbuh second review please :) |
Not sure it's the best idea from the DX perspective when I have to pass the service name instead of a simple key, but I think we can live with that. :) So to me this is ready to be merged. ping @symfony/deciders |
</service> | ||
|
||
<service id="cache.adapter.doctrine" class="Symfony\Component\Cache\Adapter\DoctrineAdapter" abstract="true"> | ||
<tag name="cache.pool" service-provider-arg-index="0" default-lifetime-arg-index="1" namespace-arg-index="2" /> |
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.
Do we really need the default-lifetime-arg-index
and namespace-arg-index
parameters? They are so ugly 😭 and uncommon in Symfony codebase.
I'm really not a big fan of the |
Please suggest any alternatives...
|
Since it should be documented maybe the "arg" part could be dropped. |
@nicolas-grekas the alternative would be to replace this handy argument resolver: foreach ($tags[0] as $argName => $argValue) {
if (isset($tags[0][$argName.'_arg_index']) && 0 <= $tags[0][$argName.'_arg_index']) {
$pool->replaceArgument($tags[0][$argName.'_arg_index'], $argValue);
}
} And replace it with a |
@javiereguiluz it's a very nice workaround to use the better name, but would |
The drawback of that is that we wouldn't be able to support every kind of custom cache adapter a user might want to create, but we would stick to the built-in adapters instead. |
This PR introduces two concepts:
This PR provides a way to manipulate both concepts separately:
Then, devs can work on optimizing the cache storages. There are two ways to do so:
On the service definitions side, a cache pool is any service that has the In short: defining |
Btw, |
b0a2860
to
0d364b4
Compare
I replaced |
@nicolas-grekas much better! Thanks. |
0d364b4
to
788080b
Compare
Just added and wired a Psr6CacheClearer so that the e.g. cache:clear command clears all cache.pool tagged services. |
new RemovePrivateAliasesPass(), | ||
new RemoveAbstractDefinitionsPass(), | ||
new ReplaceAliasByActualDefinitionPass(), |
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.
This looks like a bug fix to me, is it? Aliases should be resolved before removing private and abstract definitions, isn't it?
@nicolas-grekas to check if this is optimized for the expected default behavior, please tell me what should a developer do by hand to achieve this:
And now, what should that same developer do to achieve this:
|
@javiereguiluz in fact our expectations are too low here: Cache integration should not be limited to pre-computed information about the app itself. We should also ease caching of cluster wide items. APCu is not suited for them, because APCu doesn't allow a shared cache pool amongst e.g. several fronts. |
28de694
to
275be3e
Compare
The Cache component is now a mandatory dep of the framework bundle, and a |
610d8fc
to
0ec352f
Compare
@nicolas-grekas if the apcu is automatic this will probably bring problems when deploys are made. e.g the deploy would require php-fpm or apache restart. |
@mvrhov if you're referring to restarting for the purpose of cache clearing, this is already handled with a cache clearer, so that clearing the cache does not require any reboot but is automatic when the cache:clear command is called. |
I haven't looked at the driver implementation, but I'm pretty sure that in the case of apcu is not. Because apcu has a different cache on cli, in apache , when running via php-fpm each pool has a different cache. To clear a apcu cache one of the following has to be made
|
if ($pool->isAbstract()) { | ||
continue; | ||
} | ||
if (!isset($tags[0]['namespace'])) { |
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.
Could it make sense to apply several cache.pool
tags on the service ? If yes, we need to handle all tags, not only the first one.
If not, we may want to warn the user that subsequent tags are ignored to ease debugging
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 doesn't make sense. We can add a warning, but unless I'm wrong no other compiler passes do that...
4f82a62
to
950435d
Compare
Online & offline comments addressed (hello from Symfony Live Paris). |
@nicolas-grekas: even if you removed the apcu being default, the problem with it still persists. IMO this requires a fat warning message in the docs. Because probably most people are not aware of that problem. |
950435d
to
59f8afd
Compare
59f8afd
to
4152634
Compare
@@ -309,6 +309,20 @@ public function testProcessMergeAutowiringTypes() | |||
$this->assertEquals(array('Foo', 'Bar'), $def->getAutowiringTypes()); | |||
} | |||
|
|||
public function testProcessResolvesAliases() |
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.
@stof test case added
Thank you @nicolas-grekas. |
…h, nicolas-grekas) This PR was merged into the 3.1-dev branch. Discussion ---------- [FrameworkBundle] integrate the Cache component | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17537 | License | MIT | Doc PR | - Last commit is the diff with #17868. Commits ------- 4152634 [FrameworkBundle] Add default pool & system adapter 714b916 [FrameworkBundle] Add & use Psr6CacheClearer 4740c5c [FrameworkBundle] use abstract cache.pool decoration and aliases 92b1a20 [FrameworkBundle] Fix and add tests for cache pool wiring e44bfdc [FrameworkBundle] Add cache-pool tag and wiring 281eafa [FrameworkBundle] Integrate the Cache component bc51fde [Cache] Normalize constructor arguments order
Last commit is the diff with #17868.