Support rebuild of all caches, including APCu, via the browser

Created on 7 August 2025, 9 days ago

Problem/Motivation

It is currently a bit tedious to clear the APCu cache, which can be necessary, for example after switching from using a deprecated Drupal core module (for example Forum ) to its new contrib counterpart.

After rebuilding caches via the browser or Drush, contrib Forum 1.0.2 version of the module (modules/contrib/forum) may be listed on the Extend page, as the only Forum module, even while files used are from Drupal core Forum version (core/modules/forum).

The solution is to clear the APCu cache, by adding this in settings.php and rebuild caches:

$settings['class_loader_auto_detect'] = FALSE;

From https://www.drupal.org/docs/administering-a-drupal-site/troubleshooting-...

Steps to reproduce

  1. Create a fresh Drupal 10.5.1 installation with DDEV
  2. Install the Drupal core module Forum
  3. Replace it with its new contrib version (drupal/forum) by downloading it with Composer
  4. Run drush cache:rebuild
  5. Expect modules/contrib/forum to be used, before core/modules/forum but see that the files from the old core module may still be used
  6. Add $settings['class_loader_auto_detect'] = FALSE; in settings.php and rebuild caches
  7. See that files from modules/contrib/forum are now used

Proposed resolution

Make it easier to clear all caches including APCu, for example by visiting an URL in the browser, like https://example.org/core/rebuild-caches.php. Maybe an appended token string should be required, to prevent outsiders from running it, like with Cron?

Source of idea, @weitzman in Clear user caches like core/rebuild.php does. #2450:

If Drupal provides some endpoint on the web that we can hit to clear APCU et al for the webserver, that would be ideal.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Feature request
Status

Active

Version

11.0 🔥

Component

cache system

Created by

🇩🇰Denmark ressa Copenhagen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ressa
  • 🇩🇰Denmark ressa Copenhagen
  • 🇩🇰Denmark ressa Copenhagen

    Connecting the issue which triggered this issue.

  • Does changing the deployment identifier fix this situation? It may not. Even if it does, this feature may be helpful.

  • 🇩🇰Denmark ressa Copenhagen

    Thanks for the link @cilefen. I am not sure if it could help. Like, how do you suggest it should be used to solve the task outlined in this issue?

    My aim is to make it easier to clear all caches without editing settings.php, but simply by visiting an URL, or some other "one step" action, like clicking a button, issuing a command on the CLI, etc. and I have updated the Issue Summary to make this clearer.

    I found a comment in another issue #3492523-41: Class "Doctrine\Deprecations\Deprecation" not found which looks really interesting:

    Shouldn't Composer clear the apcu cache whenever the composer.lock hash changes?

    That would take care of the stale paths after switching from a core to a contrib module, since composer.lock will have changed.

  • 🇩🇰Denmark ressa Copenhagen

    Adding Composer issue about APCu cache.

  • 🇩🇰Denmark ressa Copenhagen

    Mention 📌 Use a better container cache key Active in the Issue Summary.

  • Like, how do you suggest it should be used to solve the task outlined in this issue?

    The reason I asked because switching the deployment identifier "fixes moved class autoloader caching". According to what I've read it is an underused configuration so in the context of evaluating the value of this feature request I thought more information would add context.

    Does browsing core/rebuild.php also do this? I think it runs apcu_clear_cache. Again, this is only to get more information.

  • 🇩🇰Denmark ressa Copenhagen

    First of all, I need to emphasize, that I am extremely grateful for your fast and investigative questions, I feel quite privileged.

    So I am sorry if I sounded irritated, when I asked the question, which I am definitely not -- I just don't know anything at all about the inner workings of Composer, Symfony, autoloaders, etc. since I am not a developer, but a simple site builder.

    My approach here is trying to report down from the Drupal trenches, trying as best as I can to investigate, and try out different things, in an actual "regular user" scenario (i.e. using recommended project in DDEV with plain vanilla settings, meaning default caching, no configuration tweaks, etc.)

    So when I asked "Like, how do you suggest ...", my point was simply this:

    How does this new method in actual effect differ from adding $settings['class_loader_auto_detect'] = FALSE; in settings.php? Because editing settings.php is what I want to avoid ...

    But it's interesting :) So I have now tried adding a dummy $settings['deployment_identifier'] = "forum_102"; in settings.php and rebuilding caches, and it works equally well as setting class_loader_auto_detect, so now there are two methods.

    core/rebuild.php or update.php do not clear caches
    Browsing core/rebuild.php nor update.php clears the caches, and so far only class_loader_auto_detect or deployment_identifier in settings.php has worked.

    Also, I have noticed that after getting everything set up for test, you need to rebuild the caches while the core (or original module) is the only one present, before proceeding with downloading contrib version and clearing caches -- I guess to populate the caches?

    Otherwise, you might check the /forum/1 path, download contrib, clear cache, and then contrib code will be in effect.

    I have updated the Issue Summary with a reproducible method, which yields the same stale caches result every time. I first tried using DDEV's snapshots feature, but it looked like the caches were not totally emptied.

    Perhaps you can give it a shot, and check if you see the same thing that I do? Feel free to ask, if anything in the process is unclear.

  • 🇩🇰Denmark ressa Copenhagen
Production build 0.71.5 2024