Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[FrameworkBundle] Dont store cache misses on warmup#40645
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
512e889 to3cec54fComparesrc/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.phpShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Nyholm commentedMar 31, 2021
@carsonbot could you find me a reviewer please? |
carsonbot commentedMar 31, 2021
I'm sorry. I could not find any suitable reviewer. |
Nyholm commentedMar 31, 2021
Oh. I guess it was too long ago@dmaicher wrote this class =) David, do you mind having a look at this PR? |
Seldaek commentedMar 31, 2021
Thanks for the quick fix :) If I understand correctly though, this means using lambdas like that will prevent caching of the resolved config and it'll reload on every request needing it. I guess it's thus worth avoiding lambda callbacks.. |
Nyholm commentedMar 31, 2021
Yes, that is correct. |
Nyholm commentedMar 31, 2021
I updated the docs with this observation:symfony/symfony-docs#15172 |
nicolas-grekas commentedMar 31, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Storing misses is an important part of the performance provided by system caches. |
Nyholm commentedMar 31, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Yes, but these "misses" are interpreted as "hits". A "hit" with null is not the same as a miss. There should never be "null" stored inthis cache. I have two alternative solutions. The first would be to find a way to serialize a |
nicolas-grekas commentedMar 31, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The test case passes even without the change if I didn't mess up :)
For system caches, aka the ones sourced by the code itself, we can do this - cache misses.
Why a closure ends up in the cache? That's the main question I have here indeed. An annotation should not lead to a closure because then of course it cannot be cached - while the source is a plain descriptive annotation. The second solution would be a major regression actually. Can you try this patch instead? It tries to not store misses for failures-to-save(). |
Nyholm commentedMar 31, 2021
You did mess up =)
Because we cache an object of
I think that would work. But the end result would be the same. We would reread the annotations at runtime. |
nicolas-grekas commentedMar 31, 2021
I confirm :P
I just read the doc PR, nice one.
True, but we would still store misses, and this is important for the other system caches.
OK great, then I suppose other system caches need this. Annotations are not the only system caches, but the current patch changes the behavior for all of them. |
… (Nyholm)This PR was squashed before being merged into the 4.4 branch.Discussion----------[Validator] Add warning about closure not being cachableFollow up fromsymfony/symfony#40645The annotation cache will not work with `Closure`.If I understand correctly, it is not possible to have external dependencies in your custom validator AND get your annotation cached. You have to chose one or the other.Commits-------ebddb78 [Validator] Add warning about closure not being cachable
| $values =array_filter($values,function ($val) { | ||
| return$val !==null; | ||
| }); | ||
| // make sure we don't cache null values | ||
| parent::warmUpPhpArrayAdapter($phpArrayAdapter,array_filter($values)); | ||
| parent::warmUpPhpArrayAdapter($phpArrayAdapter,$values); |
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.
array_filter($values) will also remove everything that isempty.
There is no test for this code and I am not sure whynull should be removed. I can only assume it is because of the callback =)
Nyholm commentedMar 31, 2021
I was wrong patching
This is not reliable. If a user does something like this, the bug will occur again. $i =$cache->getItem('foo');$i->set('data');$cache->save($i);// Save failed for some reason.// ...$cache->getItem('foo'); |
src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Nyholm commentedMar 31, 2021
The PR is updated |
…pter (nicolas-grekas)This PR was merged into the 4.4 branch.Discussion----------[Cache] skip storing failure-to-save as misses in ArrayAdapter| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |Fix#38694| License | MIT| Doc PR | -In addition to#40645Commits-------ba66987 [Cache] skip storing failure-to-save as misses in ArrayAdapter
dmaicher commentedApr 1, 2021
d249500 to27a22b3Comparenicolas-grekas commentedApr 1, 2021
Thank you@Nyholm. |
Uh oh!
There was an error while loading.Please reload this page.
When we are warming the annotation cache, we are reading all annotation into an
ArrayAdapter. When we are done we move the values to aPhpArrayAdapterto store them in a file.@Seldaekfound out that when you are using a custom constraint with a
Symfony\Component\Validator\Constraints\Callback, there is a strange error like:That is because the
Closurein theSymfony\Component\Validator\Constraints\Callbackcannot be serialised and saved to cache. But since theArrayAdapteris alsostoring misses as null, the null values are understood as real values.When all values are moved to the
PhpArrayAdapterand we ask the cache for a value (via Doctrine'sCacheProvider), it will returnnullas a value instead offalseas a cache miss. Andnullis not something one could "yield from".