The prefix used for cache items is build from a persistent variable which is never set

Created on 20 July 2024, 4 months ago
Updated 3 August 2024, 4 months ago

DrupalAPCCache::getPrefixSettingsForBin() contains the following code.

    $prefixes = variable_get('cache_prefix', '');

    if (is_string($prefixes)) {
      // Variable can be a string, which then considered as a default behavior.
      return $prefixes;
    }

    if (isset($prefixes[$bin])) {
      if (FALSE !== $prefixes[$bin]) {
        // If entry is set and not FALSE, an explicit prefix is set for the bin.
        return $prefixes[$bin];
      }
      else {
        // If we have an explicit false, it means no prefix whatever is the
        // default configuration.
        return '';
      }
    }
    else {
      // Key is not set, we can safely rely on default behavior.
      if (isset($prefixes['default']) && FALSE !== $prefixes['default']) {
        return $prefixes['default'];
      }
      else {
        // When default is not set or an explicit FALSE, this means no prefix.
        return '';
      }
    }

variable_get('cache_prefix', '') tries to get a value that neither Drupal core nor this module set, with the consequence that the used prefix will always be an empty string. The documentation for this module does not say that $conf['cache_prefix'] can be set for multi-site installations to avoid they share the same cached values. If a site uses $conf['cache_prefix'] is just because somebody read the code and noticed that variable_get('cache_prefix', '') is used from the module.

The code needs to first check $conf['apc_cache_prefix'] has been set; if it has not been set, check whether $conf['cache_prefix'] has been set.
The prefix should be build from one of those values.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇮🇹Italy apaderno Brescia, 🇮🇹

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024