-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Keep possibility to disable in-memory caching of routes #57640
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
Comments
The code that handles this static cache is here: symfony/src/Symfony/Component/Routing/Router.php Lines 294 to 305 in 68a5704
So, as far as I understand it, this is a cache for the compiled routes that only kicks in if someone disabled Opcache (which is the default on CLI and your tests). This basically means that you โ during your functional tests โ recompile the router with a different set of routes for the same kernel and environment. Does that sound about right? |
I'd need to check, but it might be that during those tests, it makes no sense to dump the compiled routes to a file either, since they'd never be re-used... but that's just overhead, no functional difference. |
I see that Is there a use case of sharing compiled route sets across different |
can't you use a different cache path for each set of routes? the code is written with the assumption that one file = one set of rules, and that assumption doesn't look insane to me |
Sharing between those two is not the motivation. It's rather that parsing a large PHP file is expensive. This is a poor man's Opcache replacement. And this also means: If you were to run your functional tests on a machine with Opcache enabled for CLI, you will run into similar problems. The static cache would be bypassed, but Opcache would say, "hey I've compiled this file already, I'm going to serve it from my bytecode cache!", which will screw you over just as this static cache does already. |
I mean, how many different sets of routes are you testing against? If we're talking about two or three or four, you could maybe use different environments for them (e.g. instead of |
I'll have to think that through... Why is it relevant to have a |
Opcache is static as well. This is as close as we can get to Opcache's behavior without actually using Opcache. |
because if file contents are immutable, caching in a static property improves sharing of the cache |
... for people who create different instances of the (Update โ Maybe I understand: Test suites that use the same set of routes again and again but have no opcache enabled benefit from keeping the routes in memory that way, to achieve caching across different
and
This is why I initially made it possible to disable file-based caching entirely in #47496. |
Only a quick, superficial check, but relevant test suites also pass when I do not set the |
You mean in the sense that once the file has been loaded during a request/process, it might be configured to give the same results again when the file is There is special code in |
We could do the same with our static cache, right? ๐ค |
But you don't know when the file is written. |
Why's that? |
I guess all I am asking for is a Router config setting to either disable file dumping/loading entirely and/or prevent caching in the |
Ah! We call |
I'll try that. Still, being able to set the |
Did you try setting the |
I added So, the idea is to remove Would work for me. |
If you meant |
we've deprecated the config option but not the parameter IIRC |
I'd rather explore the path of fixing file-based caching for your scenario instead of relying on obscure ways to disable that functionality, tbh. |
You mean #57640 (comment)? PR incoming. Or do you mean that my test suites should use different environments and/or kernel cache dirs when working through different route configurations? I'll look into that, but seems to be a bit too complex to circumvent a feature I don't want to use in the first place (file-based caching of compiled routes). |
an obscure solution for an obscure need might fit ;) |
Trust me, I've spared some details to make this bearable for you guys. |
Oh, and did you check if that change fixes your problem? |
Only superficially, but it seems so, yes. Still, I'll set the Thank you guys for the healthy discussion. As always, it was a pleasure working with you โ you're always open-minded and interested in solutions, not dismissing suggestions right away. |
I thank you for making me dig into exciting Symfony code I haven't read for ages. ๐ |
Code that feels like ๐ฅ to you, I hope ๐. |
โฆhe file-based cache (mpdude) This PR was merged into the 5.4 branch. Discussion ---------- [Routing] Discard in-memory cache of routes when writing the file-based cache | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #57640 | License | MIT The `Router` has a `private static ?array $cache` field that it uses to cache compiled route collections in the case that OpCache is not available to cache the file-based cache already. This is somewhat [a poor man's Opcache replacement](symfony/symfony#57640 (comment)), useful e. g. for speedups during (functional) tests. `\Symfony\Component\Config\ResourceCheckerConfigCache::write` contains special code to make sure the OpCache will reload files after they have been written, but the `static` property kind of "hides" this feature. With this PR, the `static` cache entry is cleared as well. Commits ------- de7d8849eb [Router]ย Discard in-memory cache of routes when writing the file-based cache
Description
Here is one use case for the feature that was postponed in #53059. Opening as a new issue so it does not get lost in the already-closed issue. We can close this one here once #53059 is re-opened.
The use case is that it may be necessary to work with different sets of routes during functional tests. The
Router
keeps the routes in aprivate static $cache
property, which makes it impossible to change the routes once one set has been loaded.Setting
$cache_dir
tonull
disables the part of the code where routes are dumped to a cache file and the results of that file are loaded intothe ::$cache
property.Example
No response
The text was updated successfully, but these errors were encountered: