Problem/Motivation
Drupal changes the composer autoloader APCu cache prefix when a module is un(installed) and when the Drupal Core version is changed. It does not change, and the cache is not cleared, when code is added or removed from the vendor directory by composer.
This means classes that have been `class_exist` looked for previously, but are now added, are still not found. And would causes classes that have been previously loaded and removed still to have a location returned.
This was noticed by the strange behavior of geocoder plugins, where when their code dependency is installed with composer they aren't detected "How to add Gecoder 3.x providers" which as you'll see cause quite some confusion. The chanced upon solutions not being very clear in the comments: install some other module; allow access to, and visit core/rebuild.php; or clear APCu (by for example restarting webserver).
Steps to reproduce
With APCu enabled. Either follow the geocoder example by adding a plugin after visiting the configuration page in the lifetime of the APCu cache; or similarly use code that checks if `class_exists` that does or does not, and add or remove as appropriate it using composer, and then check again.
Proposed resolution
No proposed resolution - yet - see first comment for thoughts.
Comments
Comment #2
ekes commentedThe first idea that jumps to mind is to in fact clear the cached autoloader results when clear cache is run. Something like:
This would already be a step forward? But it would only work from the web interface as mentioned in Drush's code here, you'd also have to run cache clear from the UI when you deploy code to another instance of the site [HT to instanceofjamie for pointing out, on Twitter where I first floated this issue, that it wouldn't help deployments].
The second idea is to include some unique value about the autoloader that composer has built. By running composer to add/remove the code the on disk autoloader has been updated. It even has a unique class name for the ComposerAutoLoaderInit (see vendor/autoloader.php). Would it be too much overhead to include that in the code that generates the prefix that Drupal uses?
Comment #7
ekes commentedPotential solution here: #3509069: Use a better container cache key
Comment #8
ekes commentedI'll close this in preference to above.
Comment #9
ressaThanks for your thorough Issue Summary @ekes, and for guiding me to the #3509069: Use a better container cache key issue, I would never have found it without your help :)
In fact, I think it could be worth considering to add parts of this Issue Summary to the container cache key issue being worked on, to add some context. Or we can hope that people searching for a solution to the APCu cache challenge finds this issue, and get guided to it?