Clear Redis cache bins on Drupal installation

Created on 9 November 2023, 8 months ago
Updated 30 April 2024, about 2 months ago

Problem/Motivation

The items in the Redis cache are by default prefixed with information derived from information that does not change between site-installs for an environment (see Settings::getApcuPrefix which is called by RedixPrefixTrait::getDefaultPrefix).

This can cause problems when an environment is reinstalled (for example during local development). For example the extension list is cached in Redis, but will be out of date during a re-install. Because none of the things the cache-key are based on change in between site installs and Redis (rightfully) doesn't empty the Redis database on install, the module list from the previous installation is preserved in the cache but is now incorrect.

Steps to reproduce

  1. Install a site using drush site-install
  2. Install a non-default module
  3. Reinstall the site using drush site-install
  4. Install the same non-default module as before

Drush will now error saying that the module is already enabled, but that is not actually the case. A drush cr will properly clear the cache and then the module can be installed on this new installation.

Proposed resolution

During module installation, we should invalidate all available cache-bins in Redis, by doing this through Redis' cache backends we ensure that only data that is for the current environment and Drupal site is invalidated.

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands Kingdutch

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

Merge Requests

Comments & Activities

  • Issue created by @Kingdutch
  • Issue was unassigned.
  • Status changed to Needs review 8 months ago
  • πŸ‡³πŸ‡±Netherlands Kingdutch
  • πŸ‡¨πŸ‡­Switzerland Berdir Switzerland

    I suspect this has a slight problem depending on the installation order of redis, cache bins that it currently doesn't know about yet (if they are provided by modules installed *after* redis is being installed) wouldn't be cleared.

  • πŸ‡³πŸ‡±Netherlands Kingdutch

    It took me some time to come up with a solution to the problem you described :D

    I think the proposed solution now also properly handles modules that are installed later. Figuring out a way to find which cache bins are defined by the installed module wasn't trivial but I found that the ModuleInstaller has code for this and if it's good enough for Drupal core's module installer, I figured it was good enough for us.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 244s
    #160857
  • πŸ‡³πŸ‡±Netherlands Kingdutch

    I'm unsure why this change seems to break the container magic that's used in the PHPUnit tests :/

Production build 0.69.0 2024