-
Notifications
You must be signed in to change notification settings - Fork 290
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
2.0 - Cache for 'all-modules' doesn't actually cache #2830
Comments
This is probably correct. |
Ignore - I found it just after I posted. |
While this fixes the error, I just realized it may not be a good idea to rely on the cache returning a specific instance that is further initialized elsewhere (as the bug demonstrated). It would be more cleaner to fully initialize the custom modules within the cache value initialization function (not sure if this is easily possible). I'll take a look at the code, this isn't urgent. |
In #2860, the hit-count module has two roles.
The logic relies on the exact-same object being available each time. I guess it is an unusual case, because the module provides two roles. Should modules be the same? i.e. the output of functions depends only on the input, and not on any previous function calls?
I agree that it is cleaner (and more maintainable) if modules are "stateless". It is easy to find these cases - they have local variables that are modified after the constuctor is called. One difficulty is that we do not boot all modules. We don't know which ones to boot until after we have created them, checked permissions and settings, etc. |
When initializing custom modules via
all()
in ModuleService.php, the modules are supposed to get cached viareturn app('cache.array')->remember('all-modules', function (): Collection {
etc
This doesn't work, leading to the initialization code getting executed repeatedly. This apparently leads to further errors (the instance of the custom module that is ultimately used is not the one on which boot() has been called, for one thing).
You can verify this via adjusting the
remember
method in Cache.php:The error log shows cache misses directly after the item is supposed to be set via
cache->get
. This is caused by ArrayAdapter.php returning false inif ($this->storeSerialized && null === $value = $this->freeze($value, $key)) {
So it's apparently caused by
freeze
not working as expected in this case. Consequently, the issue is resolved by using a non-serializing adapter in UseCache.php:$this->array_adapter = new ArrayAdapter($defaultLifetime = 0, $storeSerialized = false);
I'm not sure about the implications of this change though. As this is an in-memory cache, it may be preferable anyway not to serialize? Otherwise, we'd have to drill deeper in order to find the reason why the
freeze
doesn't work as expected in this case.The text was updated successfully, but these errors were encountered: